Finding matching keys in two large dictionaries and doing it fast

前端 未结 11 1642
鱼传尺愫
鱼传尺愫 2020-12-15 17:35

I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.

Say for example:

    myRDP = { \'Actinobacter\':          


        
11条回答
  •  粉色の甜心
    2020-12-15 18:15

    You could start by finding the common keys and then iterating over them. Set operations should be fast because they are implemented in C, at least in modern versions of Python.

    common_keys = set(myRDP).intersection(myNames)
    for key in common_keys:
        print key, myNames[key]
    

提交回复
热议问题