Skip to content

Instantly share code, notes, and snippets.

@giwa giwa/file0.txt
Created May 15, 2016

Embed
What would you like to do?
>>> def compare(a, b):
... """Comparison that ignores the first letter"""
... return cmp(a[1:], b[1:])
>>> names = ['Adam', 'Donald', 'John']
>>> names.sort(cmp=compare)
>>> names
['Adam', 'John', 'Donald']
>>> names = ['Adam', 'Donald', 'John']
>>> names.sort(key=lambda x: x[1:])
>>> names
['Adam', 'John', 'Donald']
>>> l = [('betty', 1), ('a', 1), ('butter', 2)]
>>> def custom_key(x):
... return -x[1], x[0]
...
>>> l.sort(key=custom_key)
>>> l
[('butter', 2), ('a', 1), ('betty', 1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.