Combine two dictionaries into a list of 3-tuples

Nickolay Kolev nmkolev at uni-bonn.de
Wed Nov 10 16:21:59 EST 2004


Jeff Epler wrote:

> How about
>     [(k, v, two[v]) for k, v in one.items()]
> or
>     [(k, v, two[v]) for k, v in one.items() if k in two]
> or
>     [(k, v, two.get(v, None)) for k, v in one.items()]
> depending on what you want to do when a key doesn't exist in "two"
> 
> Jeff

I should have thought of that, it is sooo simple... :-)

Thanks again.

Cheers,
   -- Nickolay



More information about the Python-list mailing list