Inverse of dict(zip(x,y))

Lorenzo loluengo at gmail.com
Wed Mar 4 09:04:29 EST 2009


Having a look at python documentation I found:

zip() in conjunction with the * operator can be used to unzip a list:

>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == x2, y == y2
True

So,
>>> x2, y2 = zip(*d.items())
should fix your problem



More information about the Python-list mailing list