Source: https://mokxi.com/learn/path/iterators-and-functional-python
Updated: 2026-11-20

All paths

# Iterators and functional Python

Comprehensions, the iterator protocol, generators in depth, map and filter, itertools and functools, ending in a streaming sensor pipeline on a Raspberry Pi with an MCP3008.

Raspberry Pi 4 Model B Free 7 lessons 5 h 4 chapters 2,373 XP Coding · Intermediate +150 XP

0 of 7 done

Start the course free Comprehensions Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### Iterators

iter() and next(), the for loop written out by hand with StopIteration, why zip and map work only once, an iterator class with __iter__ and __next__, iterables that can be looped again, and a countdown that blinks an LED.
Open it in the simulator

Chapter 2 project

### map and filter

Functions as values: map() to transform, filter() and lambda to keep, map over two lists at once, a dict of converter functions, key functions for sorted() and max(), and a lazy filter that blinks an LED once per hot reading.
Open it in the simulator

Chapter 3 project

### functools

reduce and the operator module, partial to pre-fill arguments for an ADC conversion, lru_cache turning 21,891 calls into 21, decorators with wraps and what this engine does differently, and a compose() of your own.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## Beyond the for loop

Comprehensions, and what a for loop really does underneath.

Open 236 XP

### Comprehensions

List comprehensions that filter and transform sonar pings, the if-else expression inside one, dict and set comprehensions over the planets, nested comprehensions that flatten and turn a grid, and generator expressions that light an alarm.

0 of 6 steps

Start What is in it

Project Locked 472 XP

### Iterators

iter() and next(), the for loop written out by hand with StopIteration, why zip and map work only once, an iterator class with __iter__ and __next__, iterables that can be looped again, and a countdown that blinks an LED.

0 of 6 steps

5 questions, graded as you go.

Chapter 2

## Lazy streams

Generators that pause, take values in, hand over and clean up.

Locked 236 XP

### Generators in depth

What yield really does: lazy start, infinite generators, send() for a running average, yield from with a return value, close() and finally for cleanup, and a pipeline of generator expressions that shows exactly when each value moves.

0 of 6 steps

Project Locked 472 XP

### map and filter

Functions as values: map() to transform, filter() and lambda to keep, map over two lists at once, a dict of converter functions, key functions for sorted() and max(), and a lazy filter that blinks an LED once per hot reading.

0 of 6 steps

5 questions, graded as you go.

Chapter 3

## The toolkits

itertools and functools, and what to write when one is missing.

Locked 236 XP

### itertools

The standard iterator toolkit: count and islice, cycle for a watch rota, accumulate and pairwise for running totals and differences, groupby and why it needs to be sorted, combinations and product, and chain, takewhile and dropwhile.

0 of 6 steps

Project Locked 472 XP

### functools

reduce and the operator module, partial to pre-fill arguments for an ADC conversion, lru_cache turning 21,891 calls into 21, decorators with wraps and what this engine does differently, and a compose() of your own.

0 of 6 steps

5 questions, graded as you go.

Chapter 4

## Project

A knob, an ADC and an LED, joined by a pipeline of generators.

Locked 249 XP

### Project: a streaming sensor pipeline

A knob read through an MCP3008 becomes an endless stream of readings, then flows through generator stages (volts with map and partial, a moving average with a deque, a change filter) into an LED, assembled with reduce.

0 of 7 steps

4 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### Beyond the for loop

- Comprehensions List comprehensions that filter and transform sonar pings, the if-else expression inside one, dict and set comprehensions over the planets, nested comprehensions that flatten and turn a grid, and generator expressions that light an alarm.
- Iterators iter() and next(), the for loop written out by hand with StopIteration, why zip and map work only once, an iterator class with __iter__ and __next__, iterables that can be looped again, and a countdown that blinks an LED.

Chapter 2

### Lazy streams

- Generators in depth What yield really does: lazy start, infinite generators, send() for a running average, yield from with a return value, close() and finally for cleanup, and a pipeline of generator expressions that shows exactly when each value moves.
- map and filter Functions as values: map() to transform, filter() and lambda to keep, map over two lists at once, a dict of converter functions, key functions for sorted() and max(), and a lazy filter that blinks an LED once per hot reading.

Chapter 3

### The toolkits

- itertools The standard iterator toolkit: count and islice, cycle for a watch rota, accumulate and pairwise for running totals and differences, groupby and why it needs to be sorted, combinations and product, and chain, takewhile and dropwhile.
- functools reduce and the operator module, partial to pre-fill arguments for an ADC conversion, lru_cache turning 21,891 calls into 21, decorators with wraps and what this engine does differently, and a compose() of your own.

Chapter 4

### Project

- Project: a streaming sensor pipeline A knob read through an MCP3008 becomes an endless stream of readings, then flows through generator stages (volts with map and partial, a moving average with a deque, a change filter) into an LED, assembled with reduce.

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Iterators and functional Python

Is Iterators and functional Python free?

Yes. All 7 lessons of Iterators and functional Python are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Iterators and functional Python take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Iterators, map and filter and functools.

Where do I start?

With "Comprehensions", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
