Lambda
lambda x: x * 2 is a small function with no name. Its body is one
expression, and its value is returned automatically.
The main use is as a short argument to another function, above all the key
of sorted, min, and max. The key function is called once per item, and
items are compared by what it returns. Return a tuple to sort by several
things: key=lambda p: (-p[1], p[0]) sorts by score high to low, then by name.
When not to use it: if you give it a name (double = lambda x: x * 2), write a
def instead. A def has a real name in tracebacks, room for a docstring, and
can hold more than one line. Linters flag named lambdas.
For simple field access, operator.itemgetter(1) and
operator.attrgetter("age") also work as keys.
Run it, then sort people by name length, longest first.