tubeshowcase●1,671,607 videos♡ My collection 0
← Learn to Code

Learn to Code03:22

PyCon US 2025 Tutorial Sneak Peek: "Reimplement `itertools` for fun & profit" Rodrigo Girão Serrão

PyCon US ↗

From the creator

Full Tutorial Title: Reimplementing the module `itertools` for fun and profit You know how to use a `for` loop in Python. But do you know HOW it works Do you know why it is that you can write `for` loops with `range`, `lists`, `strings`, `zip`, and `enumerate`? What's the machinery that makes that work? And have you noticed how `range(1)` and `range(99999999999999999)` take exactly the same time to run? There's something lazy about the built-in `range`... But what does “lazy” even mean? In the tutorial “Reimplementing the module `itertools` for fun and profit” you'll learn how to answer all of these questions, and much more, through the lens of the module `itertools`. The module `itertools` is implemented in C, but in this tutorial you'll reimplement it in pure Python! And you'll do that for two reasons. First, because it's an excellent, fun challenge...And on top of that, because it's surprisingly instructive. By trying to reimplement the 19 iterators in the module `itertools`, you'll learn what the word “iterable” really means. And you'll learn what “iterator” means, a word that is uncomfortably similar to “iterable”. You will also understand what the built-ins `next` and `iter` have to do with all of this! And you'll uncover Python's darkest secret: that you could translate all of your `for` loops into `while` loops. I promise those will be some 7 or 8 funky lines of code! The structure of the workshop will be very simple: I will show some concepts and some demos,

Published 2025-05-02 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code