def mycmp(a, b):
if a < b:
return -1
elif a > b:
return 1
return 0
sorted(lst, key=functools.cmp_to_key(mycmp))
# functools.cmp_to_key converts the mycmp to a "key function",
# which returns an object that can be sorted accoding to mycmp
sorted("This is a test string from Andrew".split(), key=str.lower)
['a', 'Andrew', 'from', 'is', 'string', 'test', 'This']
sorted(student_tuples, key=lambda student: student[2]) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]