dict invert - learning question

mrkafk at gmail.com mrkafk at gmail.com
Sat May 3 19:27:25 EDT 2008


Assuming all the values are unique:

>>> a={1:'a', 2:'b', 3:'c'}

>>> dict(zip(a.keys(), a.values()))

{1: 'a', 2: 'b', 3: 'c'}

The problem is you obviously can't assume that in most cases.

Still, zip() is very useful function.



More information about the Python-list mailing list