How to do an 'inner join' with dictionaries
Kent Johnson
kent at kentsjohnson.com
Mon Feb 27 08:47:01 EST 2006
cyborg4 at walla.co.il wrote:
> Let's say I have two dictionaries:
> dict1 is 1:23, 2:76, 4:56
> dict2 is 23:A, 76:B, 56:C
>
> How do I get a dictionary that is
> 1:A, 2:B, 4:C
>
>>> dict1 = {1:23, 2:76, 4:56}
>>> dict2 = {23:'A', 76:'B', 56:'C'}
>>> dict((key, dict2[value]) for key, value in dict1.iteritems())
{1: 'A', 2: 'B', 4: 'C'}
Kent
More information about the Python-list
mailing list