Swap keys for values : iteritems « Dictionary « Python Tutorial






myDictionary = {'color':'blue', 'speed':'fast', 'number':1, 5:'number'}

swapDictionary = {}
for key, val in myDictionary.iteritems():
    swapDictionary[val] = key

print swapDictionary








8.15.iteritems
8.15.1.iteritems method returns an iterator instead of a list
8.15.2.Swap keys for values
8.15.3.The keys, values, and items Functions