Mega Code Archive

 
Categories / Python Tutorial / Dictionary
 

Swap keys for values

myDictionary = {'color':'blue', 'speed':'fast', 'number':1, 5:'number'} swapDictionary = {} for key, val in myDictionary.iteritems():     swapDictionary[val] = key print swapDictionary