Iterables and iterators

Python leans heavily on iteration: a simple, efficient way to process data one element at a time.
That’s why so many everyday objects—like list, dict, str, and files iterable.

This tutorial explains:

You can run the code snippets and solve the exercises in your favorite code editor, but the tutorial is fully usable online, so you don’t need to install Python to follow it.

If you work with data (tables, logs, VCF/FASTQ files, streams…), understanding iterables and iterators will help you write code that is cleaner and more memory-efficient.

Contents

  1. Iterables and iterators
    Core concepts, the iteration protocol, and how for really works.

  2. Generators
    Creating iterators with yield, infinite sequences, and streaming patterns.

  3. Exercises
    Hands-on practice to reinforce the concepts and spot common mistakes.