[英]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)]
Note: What will be the output of max_wait_time?注意:max_wait_time 的 output 是多少? Will it work?
它会起作用吗? I am new to python and I found that there is not integer elements in res_cat so how does max_wait_time works?
我是 python 的新手,我发现 res_cat 中没有 integer 元素,那么 max_wait_time 是如何工作的?
There are few issues in the code snippet, Which are代码片段中的问题很少,分别是
rescat2idx
is a list, you need to iterate through rescat2idx[0]
rescat2idx
是一个列表,需要遍历rescat2idx[0]
f"TR_S{int(res_cat[-1]) - 1}"
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.