2 ms·
How to use Python’s min() and max() with nested lists
- littlehelper 10y agoIf you're gonna re-invent the wheel, something like this is a lot more readable in my eyes. def my_max(sequence, key=None): if not key: return max(sequence) return max(key(x) for x in sequence) Combining it with the operator module that makes it a lot nicer than the lambdas for extracting an item. import operator print(my_max([('a', 3), ('b', 2), ('c', 1)], operator.itemgetter(1)))