I have two dictionaries mapping IDs to values. For simplicity, lets say those are the dictionaries:
d_source = {'a': 1, 'b': 2, 'c': 3, '3': 3}
d_target = {'A': 1, 'B': 2, 'C': 3, '1': 1}
As named, the dictionaries are not symmetrical.
I would like to get a dictionary of keys from dictionaries d_source and d_target whose values match. The resulting dictionary would have d_source keys as its own keys, and d_target keys as that keys value (in either a list, tuple or set format).
This would be The expected returned value for the above example should be the following list:
{'a': ('1', 'A'),
'b': ('B',),
'c': ('C',),
'3': ('C',)}
There are two somewhat similar questions, but those solutions can't be easily applied to my question.
Some characteristics of the data:
- Source would usually be smaller than target. Having roughly few thousand sources (tops) and a magnitude more targets.
- Duplicates in the same dict (both
d_sourceandd_target) are not too likely on values. - matches are expected to be found for (a rough estimate) not more than 50% than
d_sourceitems. - All keys are integers.
What is the best (performance wise) solution to this problem? Modeling data into other datatypes for improved performance is totally ok, even when using third party libraries (i'm thinking numpy)