python语法: job_end_times = {job.job_id: 0 for job in jobs}
举例说明
假设 jobs
列表包含以下作业对象:
python
class Job:
def __init__(self, job_id, operations):
self.job_id = job_id
self.operations = operations
jobs = [
Job(1, []),
Job(2, []),
Job(3, [])
]
遍历 jobs
列表,并为每个作业创建一个键值对 job_id: 0
,结果如下:
job_end_times = {job.job_id: 0 for job in jobs}
生成的 job_end_times
字典为:
{1: 0, 2: 0, 3: 0}
这意味着每个作业的初始结束时间都被设置为0,便于后续的调度和计算。