Skip to content

Instantly share code, notes, and snippets.

@reidrac
Created February 29, 2012 15:33
Show Gist options
  • Save reidrac/1941700 to your computer and use it in GitHub Desktop.
Save reidrac/1941700 to your computer and use it in GitHub Desktop.
Using a dict to discard repeated items in a list of tuples
>>> 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