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

Sequences, Iterables, Iterators, Generators, Context Managers
33,727 Students enrolled
2604 reviews
  • Description
  • Curriculum
  • FAQ

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

  • sequences

  • iterables

  • iterators

  • generators

  • comprehensions

  • context managers

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.

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!

** Prerequisites **

Please note that this is a relatively advanced Python course, and a strong knowledge of some topics in Python is required. 

In particular you should already have an in-depth understanding of the following topics:

  • functions and function arguments

  • packing and unpacking iterables and how that is used with function arguments (i.e. using *)

  • closures

  • decorators

  • Boolean truth values and how any object has an associated truth value

  • named tuples

  • the zip, map, filter, sorted, reduce functions

  • lambdas

  • importing modules and packages

You should also have a basic knowledge of the following topics:

  • various data types (numeric, string, lists, tuples, dictionaries, sets, etc)

  • for loops, while loops, break, continue, the else clause

  • if statements

  • try…except…else…finally…

  • basic knowledge of how to create and use classes (methods, properties) – no need for advanced topics such as inheritance or meta classes

  • understand how certain special methods are used in classes (such as __init__, __eq__, __lt__, etc)

How long do I have access to the course materials?
You can view and review the lecture materials indefinitely, like an on-demand channel.
Can I take my courses with me wherever I go?
Definitely! If you have an internet connection, courses on Udemy are available on any device at any time. If you don't have an internet connection, some instructors also let their students download course lectures. That's up to the instructor though, so make sure you get on their good side!