Converting Dictionary to List?

Federer picture Federer · Nov 5, 2009 · Viewed 726.6k times · Source

I'm trying to convert a Python dictionary into a Python list, in order to perform some calculations.

#My dictionary
dict = {}
dict['Capital']="London"
dict['Food']="Fish&Chips"
dict['2012']="Olympics"

#lists
temp = []
dictList = []

#My attempt:
for key, value in dict.iteritems():
    aKey = key
    aValue = value
    temp.append(aKey)
    temp.append(aValue)
    dictList.append(temp) 
    aKey = ""
    aValue = ""

That's my attempt at it... but I can't work out what's wrong?

Answer

Björn picture Björn · Nov 5, 2009
dict.items()

Does the trick.