I have a huge dictionary (like a database) where I want to find some specific information. Let’s call the huge database A.
If one specific number of a new list is inside A I want to print some info. This is what I am doing (oversimplified):
A = {info1:34, info2:4, info3:-34, info4:2,.......}
b = [1, 2, 3, 4, 5, 6, -1, -2, -3, -4, -5, -6]
for i,j in A.iteritems():
if j in b:
print b, i
It seems like is working, but after a better look into the results I realized that the code only prints the first coincidence that it found. How could I change it to get all the coincidence in my database.
Thanks for your help!!!!
From what I understand what you are trying is overkill. This is a solution that makes use of the fact that
dictis actually a hash:EDIT: from your edit it seems that the keys and values are interchanged. Why are you doing this? Maybe it’s a better idea to switch them, so that my above solution works (it’s much more efficient, and you only have to do the switch once). If you need multiple identical keys, you can use a
MultiDict, likepaste.util.multidict.Multidict, installable bypip install paste