Skip to main content
CourseFlix

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

34h 42m 47s
English
Paid

Embark on a deep dive into Python 3 to explore the intricacies of iteration, from the sequence and iterable protocols to writing custom data types. Discover the nuances of sequence slicing, comprehensions, closures, and how list comprehensions have distinct scopes that can sometimes lead to unexpected bugs.

Course Overview

In Part 2 of the Python 3: Deep Dive series, we will thoroughly examine:

  • Sequences
  • Iterables
  • Iterators
  • Generators
  • Comprehensions
  • Context Managers
  • Generator-based Coroutines

This module will delve into the itertools module, uncovering the less commonly known but incredibly useful functionalities available.

We will explore generator functions, their link to iterators, and their comprehension alternatives through generator expressions.

An often overlooked construct, context managers, will be examined in detail. Here, we’ll learn to create and utilize custom context managers and understand their relationship with generator functions.

Moreover, we’ll discover how generators can be employed to create coroutines.

Each section concludes with a project designed to reinforce the concepts learned throughout the course.

This series focuses solely on the Python language and its standard library. Given the substantial functionality embedded in the CPython distribution, third-party libraries are not covered though they are integral to Python’s ecosystem.

Please note: This is an advanced Python course requiring strong foundational knowledge in key areas.

Prerequisites

You should already have an in-depth understanding of the following topics:

  • Functions and function arguments
  • Packing and unpacking iterables using *
  • Closures and decorators
  • Boolean truth values and their association with objects
  • Named tuples
  • Functions: zip, map, filter, sorted, reduce
  • Lambdas
  • Importing modules and packages

You should also have a foundational knowledge of the following:

  • Various data types: numeric, string, lists, tuples, dictionaries, sets, etc.
  • Loop constructs: for, while, break, continue, and else clauses
  • Control flow with if statements
  • Exception handling: try...except...else...finally...
  • Basic class creation and use (methods, properties)
  • Understanding special methods such as __init__, __eq__, __lt__, etc.

Course Requirements

  • This advanced course requires familiarity with basic Python concepts and a deeper understanding of specific areas. Please review the prerequisites before enrolling.
  • A working environment with Python 3.6 or later, using tools such as command line, PyCharm, or Jupyter, is necessary.

Target Audience

  • Python developers aiming to deepen their understanding of sequences, iterators, generators, and context managers.

Learning Outcomes

Upon completing this course, you will be able to:

  • Enhance your Python programming skills through advanced concepts
  • Understand sequence types and the sequence protocol
  • Master iterables and the iterable protocol
  • Explore iterators and the iterator protocol
  • Connect list comprehensions and closures
  • Create and utilize generator functions
  • Differentiate generator expressions
  • Harness context managers
  • Create context managers using generator functions
  • Implement generators as coroutines

About the Author: Udemy

Udemy thumbnail

Udemy is the largest open marketplace for online courses on the internet. Founded in 2010 by Eren Bali, Oktay Caglar, and Gagan Biyani and headquartered in San Francisco, the company went public on the Nasdaq in 2021 under the ticker UDMY. The platform hosts well over two hundred thousand courses across software development, IT and cloud, data science, design, business, marketing, and creative skills, taught by tens of thousands of independent instructors. Roughly seventy million learners use it worldwide, and the corporate arm — Udemy Business — supplies a curated subset of that catalog to enterprise customers.

Because Udemy is a marketplace rather than a single editorial publisher, the catalog is uneven by design. The strongest material lives in the long-form, project-based courses authored by working engineers — full-stack JavaScript, React, Node.js, Python data science, AWS, Docker and Kubernetes, mobile development with Flutter and React Native, and cloud certification preparation. The CourseFlix listing under this source is the slice of that catalog that has been mirrored here for offline-friendly viewing, organized by topic and updated as new releases land. Pricing on Udemy itself swings dramatically with the site's near-permanent sales, which is why the platform is best treated as a deep reference catalog: pick instructors with strong reviews and a track record of updating their material rather than buying on the headline price alone.

Watch Online 137 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 137 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Course Overview
All Course Lessons (137)
#Lesson TitleDurationAccess
1
Course Overview Demo
06:31
2
Pre-Requisites
06:05
3
Python Tools Needed
03:04
4
Introduction
01:24
5
Sequence Types - Lecture
17:11
6
Sequence Types - Coding
27:24
7
Mutable Sequence Types - Lecture
07:19
8
Mutable Sequence Types - Coding
18:07
9
Lists vs Tuples
21:51
10
Index Base and Slice Bounds - Rationale
15:15
11
Copying Sequences - Lecture
29:26
12
Copying Sequences - Coding
23:29
13
Slicing - Lecture
32:09
14
Slicing - Coding
14:43
15
Custom Sequences - Part 1 - Lecture
10:41
16
Custom Sequences - Part 1 - Coding
34:01
17
In-Place Concatenation and Repetition - Lecture
05:35
18
In-Place Concatenation and Repetition - Coding
07:28
19
Assignments in Mutable Sequences - Lecture
07:04
20
Assignments in Mutable Sequences - Coding
10:20
21
Custom Sequences - Part 2 - Lecture
09:18
22
Custom Sequences - Part 2A - Coding
17:56
23
Custom Sequences - Part 2B - Coding
34:50
24
Custom Sequences - Part 2C - Coding
21:11
25
Sorting Sequences - Lecture
17:53
26
Sorting Sequences - Coding
25:53
27
List Comprehensions - Lecture
17:56
28
List Comprehensions - Coding
47:17
29
Project Description
07:33
30
Project Solution: Goal 1
40:33
31
Project Solution: Goal 2
12:14
32
Introduction
02:54
33
Iterating Collections - Lecture
11:20
34
Iterating Collections - Coding
20:19
35
Iterators - Lecture
06:22
36
Iterators - Coding
11:45
37
Iterators and Iterables - Lecture
11:23
38
Iterators and Iterables - Coding
28:04
39
Example 1 - Consuming Iterators Manually
26:32
40
Example 2 - Cyclic Iterators
31:34
41
Lazy Iterables - Lecture
03:45
42
Lazy Iterables - Coding
15:00
43
Python's Built-In Iterables and Iterators - Lecture
02:25
44
Python's Built-In Iterables and Iterators - Coding
14:22
45
Sorting Iterables
08:52
46
The iter() Function - Lecture
06:27
47
The iter() Function - Coding
14:00
48
Iterating Callables - Lecture
04:43
49
Iterating Callables - Coding
15:54
50
Example 3 - Delegating Iterators
07:42
51
Reversed Iteration - Lecture
09:50
52
Reversed Iteration - Coding
20:01
53
Caveat: Using Iterators as Function Arguments
18:47
54
Project Description
03:30
55
Project Solution: Goal 1
05:52
56
Project Solution: Goal 2
07:43
57
Introduction
01:22
58
Yielding and Generator Functions - Lecture
17:39
59
Yielding and Generator Functions - Coding
17:34
60
Example - Fibonacci Sequence
15:32
61
Making an Iterable from a Generator - Lecture
07:00
62
Making an Iterable from a Generator - Coding
06:41
63
Example - Card Deck
11:05
64
Generator Expressions and Performance - Lecture
09:18
65
Generator Expressions and Performance - Coding
30:20
66
Yield From - Lecture
02:37
67
Yield From - Coding
12:30
68
Project Description
04:16
69
Project Solution: Goal 1
41:47
70
Project Solution: Goal 2
15:58
71
Introduction
04:23
72
Aggregators - Lecture
10:06
73
Aggregators - Coding
26:29
74
Slicing - Lecture
03:19
75
Slicing - Coding
11:34
76
Selecting and Filtering - Lecture
10:03
77
Selecting and Filtering - Coding
15:08
78
Infinite Iterators - Lecture
05:30
79
Infinite Iterators - Coding
18:50
80
Chaining and Teeing - Lecture
08:41
81
Chaining and Teeing - Coding
18:53
82
Mapping and Reducing - Lecture
15:55
83
Mapping and Reducing - Coding
18:17
84
Zipping - Lecture
03:16
85
Zipping - Coding
06:55
86
Grouping - Lecture
10:01
87
Grouping - Coding
27:02
88
Combinatorics - Lecture
09:31
89
Combinatorics - Coding (Product)
21:27
90
Combinatorics - Coding (Permutation, Combination)
20:50
91
Project - Description
11:50
92
Project Solution: Goal 1
43:51
93
Project Solution: Goal 2
38:42
94
Project Solution: Goal 3
07:18
95
Project Solution: Goal 4
50:39
96
Introduction
08:03
97
Context Managers - Lecture
22:47
98
Context Managers - Coding
37:11
99
Caveat when used with Lazy Iterators
03:50
100
Not just a Context Manager
07:34
101
Additional Uses - Lecture
06:05
102
Additional Uses - Coding
36:04
103
Generators and Context Managers - Lecture
10:47
104
Generators and Context Managers - Coding
13:14
105
The contextmanager Decorator - Lecture
09:43
106
The contextmanager Decorator - Coding
24:27
107
Nested Context Managers
34:29
108
Project - Description
07:18
109
Project Solution: Goal 1
17:51
110
Project Solution: Goal 2
11:02
111
Introduction
07:42
112
Coroutines - Lecture
25:36
113
Coroutines - Coding
17:12
114
Generator States - Lecture
03:12
115
Generator States - Coding
06:48
116
Sending to Generators - Lecture
14:49
117
Sending to Generators - Coding
20:05
118
Closing Generators - Lecture
08:28
119
Closing Generators - Coding
27:21
120
Sending Exceptions to Generators - Lecture
07:54
121
Sending Exceptions to Generators - Coding
24:18
122
Using Decorators to Prime Coroutines - Lecture
05:42
123
Using Decorators to Prime Coroutines - Coding
08:47
124
Yield From - Two-Way Communications - Lecture
10:30
125
Yield From - Two-Way Communications - Coding
15:13
126
Yield From - Sending Data - Lecture
05:57
127
Yield From - Sending Data - Coding
26:56
128
Yield From - Closing and Return - Lecture
06:24
129
Yield From - Closing and Return - Coding
14:17
130
Yield From - Throwing Exceptions - Lecture
02:48
131
Yield From - Throwing Exceptions - Coding
25:31
132
Application - Pipelines - Lecture
04:35
133
Application - Pipelines - Pulling Data
11:28
134
Application - Pipelines - Pushing Data
09:05
135
Application - Pipelines - Broadcasting Data
32:39
136
Project Description
01:50
137
Project Solution
14:19
Unlock unlimited learning

Get instant access to all 136 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription

Course content

137 lessons · 34h 42m 47s
Show all 137 lessons
  1. 1 Course Overview 06:31
  2. 2 Pre-Requisites 06:05
  3. 3 Python Tools Needed 03:04
  4. 4 Introduction 01:24
  5. 5 Sequence Types - Lecture 17:11
  6. 6 Sequence Types - Coding 27:24
  7. 7 Mutable Sequence Types - Lecture 07:19
  8. 8 Mutable Sequence Types - Coding 18:07
  9. 9 Lists vs Tuples 21:51
  10. 10 Index Base and Slice Bounds - Rationale 15:15
  11. 11 Copying Sequences - Lecture 29:26
  12. 12 Copying Sequences - Coding 23:29
  13. 13 Slicing - Lecture 32:09
  14. 14 Slicing - Coding 14:43
  15. 15 Custom Sequences - Part 1 - Lecture 10:41
  16. 16 Custom Sequences - Part 1 - Coding 34:01
  17. 17 In-Place Concatenation and Repetition - Lecture 05:35
  18. 18 In-Place Concatenation and Repetition - Coding 07:28
  19. 19 Assignments in Mutable Sequences - Lecture 07:04
  20. 20 Assignments in Mutable Sequences - Coding 10:20
  21. 21 Custom Sequences - Part 2 - Lecture 09:18
  22. 22 Custom Sequences - Part 2A - Coding 17:56
  23. 23 Custom Sequences - Part 2B - Coding 34:50
  24. 24 Custom Sequences - Part 2C - Coding 21:11
  25. 25 Sorting Sequences - Lecture 17:53
  26. 26 Sorting Sequences - Coding 25:53
  27. 27 List Comprehensions - Lecture 17:56
  28. 28 List Comprehensions - Coding 47:17
  29. 29 Project Description 07:33
  30. 30 Project Solution: Goal 1 40:33
  31. 31 Project Solution: Goal 2 12:14
  32. 32 Introduction 02:54
  33. 33 Iterating Collections - Lecture 11:20
  34. 34 Iterating Collections - Coding 20:19
  35. 35 Iterators - Lecture 06:22
  36. 36 Iterators - Coding 11:45
  37. 37 Iterators and Iterables - Lecture 11:23
  38. 38 Iterators and Iterables - Coding 28:04
  39. 39 Example 1 - Consuming Iterators Manually 26:32
  40. 40 Example 2 - Cyclic Iterators 31:34
  41. 41 Lazy Iterables - Lecture 03:45
  42. 42 Lazy Iterables - Coding 15:00
  43. 43 Python's Built-In Iterables and Iterators - Lecture 02:25
  44. 44 Python's Built-In Iterables and Iterators - Coding 14:22
  45. 45 Sorting Iterables 08:52
  46. 46 The iter() Function - Lecture 06:27
  47. 47 The iter() Function - Coding 14:00
  48. 48 Iterating Callables - Lecture 04:43
  49. 49 Iterating Callables - Coding 15:54
  50. 50 Example 3 - Delegating Iterators 07:42
  51. 51 Reversed Iteration - Lecture 09:50
  52. 52 Reversed Iteration - Coding 20:01
  53. 53 Caveat: Using Iterators as Function Arguments 18:47
  54. 54 Project Description 03:30
  55. 55 Project Solution: Goal 1 05:52
  56. 56 Project Solution: Goal 2 07:43
  57. 57 Introduction 01:22
  58. 58 Yielding and Generator Functions - Lecture 17:39
  59. 59 Yielding and Generator Functions - Coding 17:34
  60. 60 Example - Fibonacci Sequence 15:32
  61. 61 Making an Iterable from a Generator - Lecture 07:00
  62. 62 Making an Iterable from a Generator - Coding 06:41
  63. 63 Example - Card Deck 11:05
  64. 64 Generator Expressions and Performance - Lecture 09:18
  65. 65 Generator Expressions and Performance - Coding 30:20
  66. 66 Yield From - Lecture 02:37
  67. 67 Yield From - Coding 12:30
  68. 68 Project Description 04:16
  69. 69 Project Solution: Goal 1 41:47
  70. 70 Project Solution: Goal 2 15:58
  71. 71 Introduction 04:23
  72. 72 Aggregators - Lecture 10:06
  73. 73 Aggregators - Coding 26:29
  74. 74 Slicing - Lecture 03:19
  75. 75 Slicing - Coding 11:34
  76. 76 Selecting and Filtering - Lecture 10:03
  77. 77 Selecting and Filtering - Coding 15:08
  78. 78 Infinite Iterators - Lecture 05:30
  79. 79 Infinite Iterators - Coding 18:50
  80. 80 Chaining and Teeing - Lecture 08:41
  81. 81 Chaining and Teeing - Coding 18:53
  82. 82 Mapping and Reducing - Lecture 15:55
  83. 83 Mapping and Reducing - Coding 18:17
  84. 84 Zipping - Lecture 03:16
  85. 85 Zipping - Coding 06:55
  86. 86 Grouping - Lecture 10:01
  87. 87 Grouping - Coding 27:02
  88. 88 Combinatorics - Lecture 09:31
  89. 89 Combinatorics - Coding (Product) 21:27
  90. 90 Combinatorics - Coding (Permutation, Combination) 20:50
  91. 91 Project - Description 11:50
  92. 92 Project Solution: Goal 1 43:51
  93. 93 Project Solution: Goal 2 38:42
  94. 94 Project Solution: Goal 3 07:18
  95. 95 Project Solution: Goal 4 50:39
  96. 96 Introduction 08:03
  97. 97 Context Managers - Lecture 22:47
  98. 98 Context Managers - Coding 37:11
  99. 99 Caveat when used with Lazy Iterators 03:50
  100. 100 Not just a Context Manager 07:34
  101. 101 Additional Uses - Lecture 06:05
  102. 102 Additional Uses - Coding 36:04
  103. 103 Generators and Context Managers - Lecture 10:47
  104. 104 Generators and Context Managers - Coding 13:14
  105. 105 The contextmanager Decorator - Lecture 09:43
  106. 106 The contextmanager Decorator - Coding 24:27
  107. 107 Nested Context Managers 34:29
  108. 108 Project - Description 07:18
  109. 109 Project Solution: Goal 1 17:51
  110. 110 Project Solution: Goal 2 11:02
  111. 111 Introduction 07:42
  112. 112 Coroutines - Lecture 25:36
  113. 113 Coroutines - Coding 17:12
  114. 114 Generator States - Lecture 03:12
  115. 115 Generator States - Coding 06:48
  116. 116 Sending to Generators - Lecture 14:49
  117. 117 Sending to Generators - Coding 20:05
  118. 118 Closing Generators - Lecture 08:28
  119. 119 Closing Generators - Coding 27:21
  120. 120 Sending Exceptions to Generators - Lecture 07:54
  121. 121 Sending Exceptions to Generators - Coding 24:18
  122. 122 Using Decorators to Prime Coroutines - Lecture 05:42
  123. 123 Using Decorators to Prime Coroutines - Coding 08:47
  124. 124 Yield From - Two-Way Communications - Lecture 10:30
  125. 125 Yield From - Two-Way Communications - Coding 15:13
  126. 126 Yield From - Sending Data - Lecture 05:57
  127. 127 Yield From - Sending Data - Coding 26:56
  128. 128 Yield From - Closing and Return - Lecture 06:24
  129. 129 Yield From - Closing and Return - Coding 14:17
  130. 130 Yield From - Throwing Exceptions - Lecture 02:48
  131. 131 Yield From - Throwing Exceptions - Coding 25:31
  132. 132 Application - Pipelines - Lecture 04:35
  133. 133 Application - Pipelines - Pulling Data 11:28
  134. 134 Application - Pipelines - Pushing Data 09:05
  135. 135 Application - Pipelines - Broadcasting Data 32:39
  136. 136 Project Description 01:50
  137. 137 Project Solution 14:19

Related courses

  • Building data-driven web apps with Flask and SQLAlchemy thumbnail

    Building data-driven web apps with Flask and SQLAlchemy

    By: Talk Python Training
    One of the areas Python really shines is in building clean and powerful web applications. Once you know the language basics, this course will teach you everythi
    9 hours 38 minutes 43 seconds
  • OpenAI API with Python Bootcamp: ChatGPT API, GPT-4, DALL·E thumbnail

    OpenAI API with Python Bootcamp: ChatGPT API, GPT-4, DALL·E

    By: Udemy
    Welcome to the best resource for learning the OpenAI API with Python and for integrating the latest OpenAI models into your applications. This OpenAI API with
    9 hours 8 minutes 16 seconds
  • Python 3: Deep Dive (Part 4 - OOP) thumbnail

    Python 3: Deep Dive (Part 4 - OOP)

    By: Udemy
    Python 3 Deep Dive (Part 4: OOP) by Fred Baptiste — master object-oriented programming in Python: classes, inheritance, descriptors, ABCs and metaclasses.
    35 hours 15 minutes 32 seconds 5 / 5

Frequently asked questions

What is Python 3: Deep Dive (Part 2 - Iteration, Generators) about?
Embark on a deep dive into Python 3 to explore the intricacies of iteration, from the sequence and iterable protocols to writing custom data types. Discover the nuances of sequence slicing, comprehensions, closures, and how list…
Who teaches Python 3: Deep Dive (Part 2 - Iteration, Generators)?
Python 3: Deep Dive (Part 2 - Iteration, Generators) is taught by Udemy. You can find more courses by this instructor on the corresponding source page.
How long is Python 3: Deep Dive (Part 2 - Iteration, Generators)?
Python 3: Deep Dive (Part 2 - Iteration, Generators) contains 137 lessons with a total runtime of 34 hours 42 minutes. All lessons are available to watch online at your own pace.
Is Python 3: Deep Dive (Part 2 - Iteration, Generators) free to watch?
Python 3: Deep Dive (Part 2 - Iteration, Generators) is part of CourseFlix's premium catalog. A CourseFlix subscription unlocks the full video player; the course description, table of contents, and preview information are available to everyone.
Where can I watch Python 3: Deep Dive (Part 2 - Iteration, Generators) online?
Python 3: Deep Dive (Part 2 - Iteration, Generators) is available to watch online on CourseFlix at https://courseflix.net/course/python-3-deep-dive-part-2-iteration-generators. The page hosts every lesson with the integrated video player; no download is required.