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
By connecting students all over the world to the best instructors, Udemy is helping individuals reach their goals and pursue their dreams. Udemy is the leading global marketplace for teaching and learning, connecting millions of students to the skills they need to succeed. Udemy helps organizations of all kinds prepare for the ever-evolving future of work. Our curated collection of top-rated business and technical courses gives companies, governments, and nonprofits the power to develop in-house expertise and satisfy employees’ hunger for learning and development.

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