Python5 min read
Python Lambda Functions
Create small anonymous functions using lambda.
Michael Brown
December 18, 2025
0.0k0
Write quick inline functions.
Basic Lambda
```python # Regular function def add(x, y): return x + y
Lambda function add = lambda x, y: x + y
print(add(3, 5)) # 8 ```
Lambda with Map
```python numbers = [1, 2, 3, 4]
Double each number doubled = list(map(lambda x: x * 2, numbers)) print(doubled) # [2, 4, 6, 8] ```
Lambda with Filter
```python ages = [15, 22, 18, 30, 12]
Get adults only adults = list(filter(lambda age: age >= 18, ages)) print(adults) # [22, 18, 30] ```
Lambda with Sort
```python people = [ {"name": "Tom", "age": 25}, {"name": "Sarah", "age": 22}, {"name": "Mike", "age": 30} ]
Sort by age people.sort(key=lambda person: person["age"]) print(people) ```
Remember
- Use for simple operations - Regular functions for complex logic - Lambda has one expression only
#Python#Intermediate#Functions