Chapter 13

Functional programming in Python — lambda, map, filter, reduce

Pure functions that leave their input alone, `lambda`, `map`, `filter`, `functools.reduce`, the silent trap in lazy iterators, when a comprehension is clearer, and stopping mutation with tuples, all while extracting error codes from raw API logs.

35 minPython 3.12
Pro course

Python for AI Career is a Pro course

Pure functions that leave their input alone, `lambda`, `map`, `filter`, `functools.reduce`, the silent trap in lazy iterators, when a comprehension is clearer, and stopping mutation with tuples, all while extracting error codes from raw API logs.

The Python course is free and complete — this course is not made of anything taken out of it. Every chapter of a Pro course runs the full six steps:

  • Encounter — Meet the problem before the definition — what cannot be done without this.
  • Understand — Build the mental model: what Python actually does, and why this way.
  • Worked — A complete example with its real output — run, not imagined.
  • Predict — Say what happens before running it. A wrong prediction teaches more than a right one.
  • Apply — Write it and run it on your own machine. Reading it is not the same as doing it.
  • Stretch — Ten questions from easy to hard. The last ones are difficult on purpose.