What will be the result in indexing the string elements of Ordered Dictionary

41 Views Asked by At
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? 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?

1

There are 1 best solutions below

6
Rahul K P On

There are few issues in the code snippet, Which are

  1. rescat2idx is a list, you need to iterate through rescat2idx[0]
  2. trans_time dict key change to this 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