Skip to content

Most items $2 · Packs priced separately

pocketshelf

Python Comprehensions and Iterators Cheat Sheet

python-comprehensions-and-iterators-cheat-sheet.pdfShowing 16 of 62 lines
// List comprehension with a filter
evens = [n for n in range(10) if n % 2 == 0]

// Nested comprehension
flat = [x for row in [[1, 2], [3, 4]] for x in row]

// Conditional expression
labels = ["big" if n > 5 else "small" for n in [3, 9]]

// Set and dict comprehensions
unique_lengths = {len(w) for w in ["a", "bb", "cc"]}
index = {w: i for i, w in enumerate(["a", "b"])}

// Generator expression
total = sum(n * n for n in range(1_000_000))

What's inside

  • Python Comprehensions and Iterators Cheat Sheet, preview page 1 with code examples in two columnsPage 1
  • Python Comprehensions and Iterators Cheat Sheet, preview page 2 with code examples in two columnsPage 2
Format
PDF, Markdown
Contents
15 sections · 2 pages
Version
1.0 · Updated 3 Oct 2026
Licence
Commercial What this means
Checked
Checked before it ships
Files in your download
  • python-comprehensions-and-iterators-cheat-sheet.pdfPDF · 20 KB
  • python-comprehensions-and-iterators-cheat-sheet.mdMarkdown · 2 KB
  • LICENSE.txtadded to every download

About this item

A compact, printable reference for comprehensions, generators and itertools. Each of the 15 entries has a one-line explanation and a small example you can paste into your editor. The PDF uses a two-column A4 layout designed to sit next to your keyboard, and the same content ships as Markdown so you can search it or drop it into your notes. Every Python example targets Python 3.12.

  • Comprehensions
  • Itertools
  • Python
  • Generators
  • Cheat sheet

You might also grab