I am writing a triple for
loop in Python. Since the data set is larger, it takes more than 1.5 hours to finish. Is there any fast way to avoid the loop?
idx = []
for key, value in bid_img.iteritems():
for v in value:
loc = 0
for pid in pid_lst:
loc += 1
if v == pid:
idx.append(loc)
What I have:
bid_img
a dictionary that contain multiple values per key.pid_lst
a list.
I want to index items for values in dic, if they match with list provided, then store them in idx
and loc
for index.
Sample input:
bid_img = {'123': ['4123','12312','1231234'], '2312':['413','112','12334']};
Sample output:
idx = [5, 11,62, 32]
- The input is larger than \$10^6\$.
- The order of output is very important; I want the exact order.
- I want to find the index or location (for each value in dict) in list
pid_lst
.
big_img
is a dictionary, anditeritems()
on a dictionary doesn't guarantee any particular order. Can you please explain your motivation further? \$\endgroup\$