Lambdas
Lambdas can help us succinctly write complex logic
- names = [("David", "Cao"), ("Ben", "Smith"), ("Justin", "Adam")]
- names.sort()
- [('Ben', 'Smith'), ('David', 'Cao'), ('Justin', 'Adam')]
- names.sort(key=lambda x: x[1])
- [('Justin', 'Adam'), ('David', 'Cao'), ('Ben', 'Smith')]