Iterators and generators by Reuven M. Lerner

Iterators and generators

Explore Python's iterator protocol in depth, including classes, generators, coroutines, and itertools.

Take full advantage of "for" loops

Python's "for" loops seem quite simple. But actually, the iterator protocol is deeply embedded in the language. This course, with more than six hours of videos and a dozen different hands-on exercises, will teach you what you need to take advantage of the protocol in your own code — with iterator classes, generator functions, coroutines, generator functions, and even the "itertools" module.

If you've been programming in Python for a while, then you'll want to take this course. It'll pull back the curtain on how the language works, and will let you write more flexible, elegant, and efficient code.

What's included?

Video Icon 82 videos File Icon 14 files

Contents

00 Welcome
2 mins
Section 1: Iterators
Section 1 — Iterators.ipynb
73.5 KB
01 Intro to iteration
5 mins
02 iter
4 mins
03 next
6 mins
04 iterable vs. iterator
4 mins
05 Simple iterator
12 mins
06 Exercise 1
2 mins
exercises-1.txt
419 Bytes
07 Exercise 1 solution
4 mins
08 Iterators as filters
4 mins
09 Exercises 2
2 mins
exercises-2.txt
650 Bytes
10 Exercise 2 solutions
7 mins
11 Should __iter__ return self?
9 mins
12 Using a helper class
8 mins
13 Exercise 3
2 mins
exercises-3.txt
568 Bytes
14 Exercise 3 solution
4 mins
16 Additional methods
4 mins
17 One class, multiple iterators
6 mins
15 Sorting results
11 mins
18 Data changing size during iteration
8 mins
19 Exercises 4
2 mins
exercises-4.txt
954 Bytes
20 Exercise 4 solution
12 mins
Section 2: Generators
Section 2 — Generators.ipynb
92.1 KB
21 Generator functions
7 mins
22 Generators maintain state
9 mins
23 return vs. yield
6 mins
24 Parameters and generator functions
3 mins
25 Exercise 5
2 mins
26 Exercise 5 solution
5 mins
27 Chunking data with generators
5 mins
28 Exercise 6
2 mins
29 Exercise 6 solution
6 mins
30 Generators for buffering
12 mins
31 Wrapping complex functionality
4 mins
32 Exercise 7
2 mins
exercises-7.txt
558 Bytes
33 Exercise 7 solution
9 mins
34 Generator functions vs. iterator classes
5 mins
35 Exercise 8
1 min
exercises-8.txt
471 Bytes
36 Exercise 8 solution
4 mins
37 Exceptions and generators
4 mins
38 Rewriting "for"
5 mins
39 Generator methods
7 mins
40 Exercise 9
3 mins
41 Exercise 9 solution
8 mins
Section 3: Coroutines
43 Using coroutines
6 mins
42 Coroutines and "send"
10 mins
44 Using "throw" with coroutines
8 mins
45 Using "close"
5 mins
46 Exercise 10
2 mins
exercises-10.txt
583 Bytes
47 Exercise 10 solution
4 mins
48 Chatbots as coroutines
4 mins
49 Subgenerators and "yield from"
4 mins
50 Coroutines and "yield from"
9 mins
51 "yield" vs "yield from"
4 mins
52 Exercise 11
3 mins
exercises-11.txt
902 Bytes
53 Exercise 11 solution
8 mins
54 Functions vs. generator functions
6 mins
55 Looking inside of generators
6 mins
Section 3 -- Coroutines.ipynb
65.1 KB
Section 4: Generator comprehensions
Section 4 — Generator comprehensions.ipynb
38.7 KB
56 Generator comprehensions
4 mins
57 Using generator comprehensions
4 mins
58 Removing double parentheses
4 mins
59 The use case for generator expressions
7 mins
60 Retrieving from files
5 mins
61 Exercise 12
3 mins
62 Exercise 12 solution
5 mins
63 Nested generator expressions
4 mins
64 Nested expressions and complex data
4 mins
65 Multiple conditions in nested generator expressions
4 mins
66 Returning generators from functions
3 mins
67 Returning generators from methods
5 mins
68 Exercises 13
2 mins
69 Exercises 13 solutions
9 mins
alice-in-wonderland.txt
73 KB
mini-access-log.txt
35.7 KB
Section 5: itertools
70 itertools
3 mins
71 itertools.chain
5 mins
72 itertools.count
5 mins
73 cycle and repeat
5 mins
74 filterfalse
3 mins
75 takewhile and dropwhile
4 mins
76 compress
3 mins
77 accumulate
3 mins
78 tee
3 mins
79 permutations and combinations
6 mins
80 more-itertools
3 mins
81 Conclusion
2 mins