I’m learning about lambdas in Python, but I don’t understand what’s going on in this example.
Can anyone explain what's going on here in plain English? The example says it's “passing a small function as an argument”, but I don’t understand what that means.
>>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
>>> pairs.sort(key=lambda pair: pair[1])
>>> pairs
[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]