Skip to content

Instantly share code, notes, and snippets.

@bearzk
Created September 13, 2012 20:38
Show Gist options
  • Save bearzk/3717458 to your computer and use it in GitHub Desktop.
Save bearzk/3717458 to your computer and use it in GitHub Desktop.
Python sort using the nth element
>>> a = [(111,555),(333,222)]
>>> a.sort()
>>> a
[(111, 555), (333, 222)]
>>> a.sort(lambda x,y: cmp(x[1],y[1]))
>>> a
[(333, 222), (111, 555)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment