Reuven Lerner's Python Courses/Iterators and generators

  • $240

Iterators and generators

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

Get this course, and many others, as part of my LernerPython membership, at https://LernerPython.com.

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.

Contents

00 Welcome

Section 1: Iterators

Section 1 — Iterators.ipynb
01 Intro to iteration
02 iter
03 next
04 iterable vs. iterator
Preview
05 Simple iterator
06 Exercise 1
exercises-1.txt
07 Exercise 1 solution
08 Iterators as filters
09 Exercises 2
exercises-2.txt
10 Exercise 2 solutions
11 Should __iter__ return self?
12 Using a helper class
13 Exercise 3
exercises-3.txt
14 Exercise 3 solution
15 Sorting results
16 Additional methods
17 One class, multiple iterators
18 Data changing size during iteration
19 Exercises 4
exercises-4.txt
20 Exercise 4 solution

Section 2: Generators

Section 2 — Generators.ipynb
21 Generator functions
22 Generators maintain state
Preview
23 return vs. yield
24 Parameters and generator functions
25 Exercise 5
26 Exercise 5 solution
27 Chunking data with generators
28 Exercise 6
29 Exercise 6 solution
30 Generators for buffering
31 Wrapping complex functionality
32 Exercise 7
exercises-7.txt
33 Exercise 7 solution
34 Generator functions vs. iterator classes
35 Exercise 8
exercises-8.txt
36 Exercise 8 solution
37 Exceptions and generators
38 Rewriting "for"
39 Generator methods
40 Exercise 9
41 Exercise 9 solution

Section 3: Coroutines

42 Coroutines and "send"
43 Using coroutines
44 Using "throw" with coroutines
45 Using "close"
46 Exercise 10
exercises-10.txt
47 Exercise 10 solution
48 Chatbots as coroutines
49 Subgenerators and "yield from"
50 Coroutines and "yield from"
51 "yield" vs "yield from"
52 Exercise 11
exercises-11.txt
53 Exercise 11 solution
54 Functions vs. generator functions
55 Looking inside of generators
Section 3 -- Coroutines.ipynb

Section 4: Generator comprehensions

Section 4 — Generator comprehensions.ipynb
56 Generator comprehensions
57 Using generator comprehensions
58 Removing double parentheses
Preview
59 The use case for generator expressions
60 Retrieving from files
61 Exercise 12
62 Exercise 12 solution
63 Nested generator expressions
64 Nested expressions and complex data
65 Multiple conditions in nested generator expressions
66 Returning generators from functions
67 Returning generators from methods
68 Exercises 13
69 Exercises 13 solutions
alice-in-wonderland.txt
mini-access-log.txt

Section 5: itertools

70 itertools
71 itertools.chain
72 itertools.count
73 cycle and repeat
74 filterfalse
75 takewhile and dropwhile
76 compress
77 accumulate
78 tee
79 permutations and combinations
80 more-itertools
81 Conclusion