I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.
Say for example:
myRDP = { \'Actinobacter\':
You could do this:
for key in myRDP:
if key in myNames:
print key, myNames[key]
Your first attempt was slow because you were comparing every key in myRDP with every key in myNames. In algorithmic jargon, if myRDP has n elements and myNames has m elements, then that algorithm would take O(n×m) operations. For 600k elements each, this is 360,000,000,000 comparisons!
But testing whether a particular element is a key of a dictionary is fast -- in fact, this is one of the defining characteristics of dictionaries. In algorithmic terms, the key in dict
test is O(1), or constant-time. So my algorithm will take O(n) time, which is one 600,000th of the time.