Created
February 29, 2012 15:33
-
-
Save reidrac/1941700 to your computer and use it in GitHub Desktop.
Using a dict to discard repeated items in a list of tuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> a = [(1, 'red'), (2, 'red'), (1, 'blue'), (3, 'green')] | |
>>> b = dict(a) | |
>>> b | |
{1: 'blue', 2: 'red', 3: 'green'} | |
>>> | |
# keep in mind 2d occurrence of the key will be the one remaining in the dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment