Inverse of dict(zip(x,y))

Andreas Tawn andreas.tawn at
Wed Mar 4 12:42:53 CET 2009

>>>So, if x and y are two lists, it is easier to make a dictionary using
>>>d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1,
>>>x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...]
>>>and y = [y1, y2, ...]
>> x = d.keys()
>> y = d.values()
>But be aware that you lose order and of course duplicate keys:

True, but that's a result of creating the dictionary, not extracting the
keys and values later.

>>> d = dict(zip("abca", "xyzt"))
>>> d
{'a': 't', 'c': 'z', 'b': 'y'}

More information about the Python-list mailing list