T
Tim Chase
Let's say I have two dictionaries:
If you don't know that all the values in d1 will be in d2,
you can put in a "if" check like
{1: 'a', 2: 'b', 4: 'c'}
(using "d1v" for "dictionary1's value" and "d1k" for
"dictionary1's key")
HTH,
-tkc
{1: 'a', 2: 'b', 4: 'c'}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>>> d1={1:23,2:76,4:56}
>>> d2={23:"a", 76:"b", 56:"c"}
>>> result = dict([(d1k,d2[d1v]) for (d1k, d1v) in d1.items()])
>>> result
If you don't know that all the values in d1 will be in d2,
>>> d1[5]=444
>>> d2[333]='qqq'
you can put in a "if" check like
d1.items() if d1v in d2])>>> result = dict([(d1k,d2[d1v]) for (d1k, d1v) in
{1: 'a', 2: 'b', 4: 'c'}
(using "d1v" for "dictionary1's value" and "d1k" for
"dictionary1's key")
HTH,
-tkc