Python 3: Deep Dive (Part 2 – Iteration, Generators)

Python 3: Deep Dive (Part 2 – Iteration, Generators)

English | MP4 | AVC 1280×720 | AAC 44KHz 2ch | 142 lectures (36h 9m) | 12.53 GB

Sequences, Iterables, Iterators, Generators, Context Managers and Generator-based Coroutines

Part 2 of this Python 3: Deep Dive series is an in-depth look at:

  • sequences
  • iterables
  • iterators
  • generators
  • comprehensions
  • context managers
  • generator based coroutines

I will show you exactly how iteration works in Python – from the sequence protocol, to the iterable and iterator protocols, and how we can write our own sequence and iterable data types.

We’ll go into some detail to explain sequence slicing and how slicing relates to ranges.

We look at comprehensions in detail as well and I will show you how list comprehensions are actually closures and have their own scope, and the reason why subtle bugs sometimes creep in to list comprehensions that we might not expect.

We’ll take a deep dive into the itertools module and look at all the functions available there and how useful (but overlooked!) they can be.

We also look at generator functions, their relation to iterators, and their comprehension counterparts (generator expressions).

Context managers, an often overlooked construct in Python, is covered in detail too. There we will learn how to create and leverage our own context managers and understand the relationship between context managers and generator functions.

Finally, we’ll look at how we can use generators to create coroutines.

Each section is followed by a project designed to put into practice what you learn throughout the course.

This course series is focused on the Python language and the standard library. There is an enormous amount of functionality and things to understand in just the standard CPython distribution, so I do not cover 3rd party libraries – this is a Python deep dive, not an exploration of the many highly useful 3rd party libraries that have grown around Python – those are often sufficiently large to warrant an entire course unto themselves! Indeed, many of them already do!

What you’ll learn

  • You’ll be able to leverage the concepts in this course to take your Python programming skills to the next level.
  • Sequence Types and the sequence protocol
  • Iterables and the iterable protocol
  • Iterators and the iterator protocol
  • List comprehensions and their relation to closures
  • Generator functions
  • Generator expressions
  • Context managers
  • Creating context managers using generator functions
  • Using Generators as Coroutines
Table of Contents

Introduction
1 Course Overview
2 Pre-Requisites
3 Python Tools Needed
4 Course Slides

Sequence Types
5 Introduction
6 Sequence Types – Lecture
7 Sequence Types – Coding
8 Mutable Sequence Types – Lecture
9 Mutable Sequence Types – Coding
10 Lists vs Tuples
11 Index Base and Slice Bounds – Rationale
12 Copying Sequences – Lecture
13 Copying Sequences – Coding
14 Slicing – Lecture
15 Slicing – Coding
16 Custom Sequences – Part 1 – Lecture
17 Custom Sequences – Part 1 – Coding
18 In-Place Concatenation and Repetition – Lecture
19 In-Place Concatenation and Repetition – Coding
20 Assignments in Mutable Sequences – Lecture
21 Assignments in Mutable Sequences – Coding
22 Custom Sequences – Part 2 – Lecture
23 Custom Sequences – Part 2A – Coding
24 Custom Sequences – Part 2B – Coding
25 Custom Sequences – Part 2C – Coding
26 Sorting Sequences – Lecture
27 Sorting Sequences – Coding
28 List Comprehensions – Lecture
29 List Comprehensions – Coding

Project 1
30 Project Description
31 Project Solution Goal 1
32 Project Solution Goal 2

Iterables and Iterators
33 Introduction
34 Iterating Collections – Lecture
35 Iterating Collections – Coding
36 Iterators – Lecture
37 Iterators – Coding
38 Iterators and Iterables – Lecture
39 Iterators and Iterables – Coding
40 Example 1 – Consuming Iterators Manually
41 Example 2 – Cyclic Iterators
42 Lazy Iterables – Lecture
43 Lazy Iterables – Coding
44 Python’s Built-In Iterables and Iterators – Lecture
45 Python’s Built-In Iterables and Iterators – Coding
46 Sorting Iterables
47 The iter() Function – Lecture
48 The iter() Function – Coding
49 Iterating Callables – Lecture
50 Iterating Callables – Coding
51 Example 3 – Delegating Iterators
52 Reversed Iteration – Lecture
53 Reversed Iteration – Coding
54 Caveat Using Iterators as Function Arguments

Project 2
55 Project Description
56 Project Solution Goal 1
57 Project Solution Goal 2

Generators
58 Introduction
59 Yielding and Generator Functions – Lecture
60 Yielding and Generator Functions – Coding
61 Example – Fibonacci Sequence
62 Making an Iterable from a Generator – Lecture
63 Making an Iterable from a Generator – Coding
64 Example – Card Deck
65 Generator Expressions and Performance – Lecture
66 Generator Expressions and Performance – Coding
67 Yield From – Lecture
68 Yield From – Coding

Project 3
69 Project Description
70 Project Solution Goal 1
71 Project Solution Goal 2

Iteration Tools
72 Introduction
73 Aggregators – Lecture
74 Aggregators – Coding
75 Slicing – Lecture
76 Slicing – Coding
77 Selecting and Filtering – Lecture
78 Selecting and Filtering – Coding
79 Infinite Iterators – Lecture
80 Infinite Iterators – Coding
81 Chaining and Teeing – Lecture
82 Chaining and Teeing – Coding
83 Mapping and Reducing – Lecture
84 Mapping and Reducing – Coding
85 Zipping – Lecture
86 Zipping – Coding
87 Grouping – Lecture
88 Grouping – Coding
89 Combinatorics – Lecture
90 Combinatorics – Coding (Product)
91 Combinatorics – Coding (Permutation, Combination)

Project 4
92 Project – Description
93 Project Solution Goal 1
94 Project Solution Goal 2
95 Project Solution Goal 3
96 Project Solution Goal 4

Context Managers
97 Introduction
98 Context Managers – Lecture
99 Context Managers – Coding
100 Caveat when used with Lazy Iterators
101 Not just a Context Manager
102 Additional Uses – Lecture
103 Additional Uses – Coding
104 Generators and Context Managers – Lecture
105 Generators and Context Managers – Coding
106 The contextmanager Decorator – Lecture
107 The contextmanager Decorator – Coding
108 Nested Context Managers

Project 5
109 Project – Description
110 Project Solution Goal 1
111 Project Solution Goal 2

Python Updates
112 Python 3.10
113 Python 3.9
114 Python 3.8 3.7

Generators as Coroutines (DEPRECATED)
115 IMPORTANT NOTE – READ FIRST
116 Introduction
117 Coroutines – Lecture
118 Coroutines – Coding
119 Generator States – Lecture
120 Generator States – Coding
121 Sending to Generators – Lecture
122 Sending to Generators – Coding
123 Closing Generators – Lecture
124 Closing Generators – Coding
125 Sending Exceptions to Generators – Lecture
126 Sending Exceptions to Generators – Coding
127 Using Decorators to Prime Coroutines – Lecture
128 Using Decorators to Prime Coroutines – Coding
129 Yield From – Two-Way Communications – Lecture
130 Yield From – Two-Way Communications – Coding
131 Yield From – Sending Data – Lecture
132 Yield From – Sending Data – Coding
133 Yield From – Closing and Return – Lecture
134 Yield From – Closing and Return – Coding
135 Yield From – Throwing Exceptions – Lecture
136 Yield From – Throwing Exceptions – Coding
137 Application – Pipelines – Lecture
138 Application – Pipelines – Pulling Data
139 Application – Pipelines – Pushing Data
140 Application – Pipelines – Broadcasting Data

Project 6 (DEPRECATED – relates to preceding deprecated section)
141 Project Description
142 Project Solution

Homepage