2. Lambdas

Use lambda for short throwaway callables passed inline to another function. If the function deserves a name, prefer def.

Keeping lambdas small prevents them from becoming unnamed mini-functions that hide logic in the middle of another call. The decision point is simple: if the callable needs explanation, branching, or reuse, it usually deserves a real name.

2.1. Don’t do this

1add_one = lambda x: x + 1
2
3add_one(3)

2.2. Do this

1def add_one(x):
2    return x + 1
3
4add_one(3)
1numbers = ['10', '2', '1']
2numbers = sorted(numbers, key=lambda value: int(value))
3
4print(numbers)