Is there a more elegant way for unpacking keys and values of a dictionary into two lists, without losing consistence?

Aufwind picture Aufwind · Jul 7, 2011 · Viewed 39.3k times · Source

What I came up with is:

keys, values = zip(*[(key, value) for (key, value) in my_dict.iteritems()])

But I am not satisfied. What do the pythonistas say?

Answer

FogleBird picture FogleBird · Jul 7, 2011
keys, values = zip(*d.items())