'inverting' a dict

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Wed Dec 31 08:14:14 EST 2003


Wade Leftwich wrote:

> def invert_dict(D):
>     return dict([(y,x) for (x,y) in D.items()])

No, this one only works for non-sequence-type values.
I wanted to map every item of a value (a sequence)
to the corresponding key.

--Irmen





More information about the Python-list mailing list