To think of something that i use lambda quite often in sorting comes to mind.
There is an alternative itemgetter,but then have to import it.
There is an alternative itemgetter,but then have to import it.
>>> lst = [('Tom', 'C', 10), ('Kent', 'A', 12), ('Jenny', 'B', 15)] >>> sorted(lst, key=lambda tup: tup[1]) [('Kent', 'A', 12), ('Jenny', 'B', 15), ('Tom', 'C', 10)]