Op 2006-02-27, [EMAIL PROTECTED] schreef <[EMAIL PROTECTED]>:
> 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
Well how about the straight forward:
dict3 = {}
for key, value in dict1.iteritems():
try:
dict3[key] = dict2[value]
except KeyError:
pass
Or otherwise with a genexp
dict3 = dict((key, dict2[value]) for (key, value) in dict1.iteritems() if value
in dict2)
--
Antoon Pardon
--
http://mail.python.org/mailman/listinfo/python-list