Víctor Terrón - Kung Fu at Dawn with Itertools [EuroPython 2016] [18 July 2016] [Bilbao, Euskadi, Spain] (https://ep2016.europython.eu//conference/talks/kung-fu-at-dawn-with-itertools)
The itertools module is one of the cornerstones of advanced programming in Python. This talk offers practical advice about iterator algebra that can be put into practice immediately. Discovering the itertools module means taking the veil from our eyes, and once we use functions such as repeat(), takewhile(), dropwhile() or product(), there is no return — it is impossible to come back to the world of the mere mortals, where solutions are more complex and need more memory.
The itertools module is one of the cornerstones of advanced programming in Python. Part of the standard library, it provides an iterator algebra that allows us to elegantly chain abstractions, enabling solutions that are both simpler and more memory efficient.
The goal of this talk is to offer practical advice and clear lessons that can be immediately put into practice. Illustrating it with numerous examples, attendees will leave having assimilated at least several concepts that will improve their code undeniably and irremediably. Emphasis will be on showing specific cases where a traditional solution can be overhauled over and over with functions from the itertools module.
Let’s say, for example, that we want to alternate indefinitely between two values: -1 and 1. The novice would use a variable, updating its value at each step, and the average user would maybe opt for an endless generator. Both are worthy and honorable solutions, but they pale before the mastery of the martial artist who only needs itertools.cycle(). Because that is the nature of the itertools module: once the veil falls from our eyes and we come across functions such as repeat(), takewhile(), dropwhile() or product(), there is no return. In this talk we will learn to identify when they can be used, accomplishing with a single line of code what for the mere mortals takes much more effort.