- Phase: 8. Data, Web & APIs
- Duration: 2 hours
- Understand functional programming concepts: pure functions, no side effects, immutability
- Apply map, filter, and reduce for data transformations
- Create partial functions with functools.partial
- Compose functions to build complex operations
- Use the operator module for cleaner code
- Leverage functools module utilities
- Pure functions and side effect avoidance
- Immutability principles
- map(), filter(), and reduce() in depth
- functools.partial for partial application
- Function composition techniques
- operator module (add, itemgetter, attrgetter)
- functools.lru_cache, functools.singledispatch
Modules 000-070 covering basics, data structures, functions, OOP, error handling, file I/O, JSON, context managers, modules/packages, venv/pip, stdlib, regex, dates, and logging.
# Pure function: no side effects, same input -> same output
def add_one(x: int) -> int:
return x + 1
# map with lambda
squared = list(map(lambda x: x**2, [1, 2, 3, 4]))
# Partial function
from functools import partial
def power(base: int, exp: int) -> int:
return base ** exp
square = partial(power, exp=2)- Python docs: functools
- Python docs: operator
- "Functional Programming HOWTO" in Python docs