Combine two dictionaries into a list of 3-tuples
Nickolay Kolev
nmkolev at uni-bonn.de
Wed Nov 10 16:08:58 EST 2004
Hi all,
Continuing the search for interesting challenges with lists, tuples and
dictionaries I am looking for a way to do the following.
one = {
'a' : 1,
'b' : 2,
'c' : 3
}
two = {
'a' : [4,5,6],
'b' : [8,9,10],
'c' : [11,12,13]
}
The goal is
[('a', 1, [4,5,6]), ('b', 2, [8,9,10]), ('c', 3, [11,12,13])]
My attempts so far:
[(t, c, l) for t, c in one.items() if (t, l) in two.items()]
gives me a 'l is not defined'
---------------
[(t, c, l) for t, c in one.items() for (t, l) in two.items()]
gives me a lot more than I need :-)
---------------
Many thanks in advance!
Cheers,
-- Nickolay
More information about the Python-list
mailing list