Return to Snippet

Revision: 37349
at December 8, 2010 21:00 by Voil


Initial Code
dict = {'a': 1, 'b': 2, 'c': 3}
print({value:key for key, value in dict.items()})
# Prints: {1: 'a', 2: 'b', 3: 'c'}

Initial URL
http://diveintopython3.org/comprehensions.html#stupiddicttricks

Initial Description
Based on the example by [Mark Pilgrim](http://diveintopython3.org/about.html).

Initial Title
Swapping keys and values of a dictionary

Initial Tags


Initial Language
Python