[英]What will be the result in indexing the string elements of Ordered Dictionary
rescat2idx= [OrderedDict([('EAF', [1]),
('AOD', [2]),
('LF', [3]),
('CC1', [4]),
('CC2', [5]),
('H_A_S1', range(6, 30)),
('H_A_S2', range(30, 54)),
('H_B_S2', range(54, 78)),
('H_A_S3', range(78, 102)),
('H_B_S3', range(102, 126)),
('H_A_S4', range(126, 150)),
('H_B_S4', range(150, 174)),
('EN', [174])]),174]
trans_time = {'TR_S1': 10, 'TR_S2': 4, 'TR_S3': 10}
trans_time_max = {'TR_S1': 240, 'TR_S2': 240, 'TR_S3': 120}
for res_cat, resources in rescat2idx.items():
if 'H_B_' not in res_cat:
continue
max_wait_time = time_trans_max['TR_S%d' % **(int(res_cat[-1])** - 1)]
注意:max_wait_time 的 output 是多少? 它會起作用嗎? 我是 python 的新手,我發現 res_cat 中沒有 integer 元素,那么 max_wait_time 是如何工作的?
代碼片段中的問題很少,分別是
rescat2idx
是一個列表,需要遍歷rescat2idx[0]
f"TR_S{int(res_cat[-1]) - 1}"
In [54]: for res_cat, resources in rescat2idx[0].items():
...: if "H_B_" not in res_cat:
...: continue
...: max_wait_time = trans_time_max[f"TR_S{int(res_cat[-1]) - 1}"]
In [55]: max_wait_time
Out[55]: 120
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.