Lambda Functions
Anonymous single-expression functions defined with lambda.
Syntax
lambda arguments: expressionExamples
square = lambda x: x ** 2
print(square(5)) # 25
add = lambda a, b: a + b
print(add(3, 4)) # 7With map / filter / sorted
nums = [1, 2, 3, 4, 5]
# map: apply to each element
squares = list(map(lambda x: x**2, nums))
# filter: keep matching
evens = list(filter(lambda x: x % 2 == 0, nums))
# sorted with key
people = [("Bob", 25), ("Alice", 30), ("Eve", 20)]
people.sort(key=lambda p: p[1])