Skip to content

Instantly share code, notes, and snippets.

@durden
Created March 8, 2013 22:27
Show Gist options
  • Save durden/5120427 to your computer and use it in GitHub Desktop.
Save durden/5120427 to your computer and use it in GitHub Desktop.
Funny python 'tricks'
# Turn list of rows into columns
>>> x = [(1,2,3), (4,5,6)]
>>> zip(*x)
[(1, 4), (2, 5), (3, 6)]
# Reverse key-value mapping in a dict
>>> x = {'a': 1, 'b': 2}
>>> dict([reversed(kv) for kv in x.iteritems()])
{1: 'a', 2: 'b'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment