Cheatography
https://sukiwaterhouse.pages.dev
Basic cheatsheet for python itertools.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Definition
The itertools module is a collection of tools intended to be fast and use memory efficiently when handling iterators (like lists or dictionaries). Example: import itertools
|
From the Python 3 documentation The module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an “iterator algebra” making it possible to construct specialized tools succinctly and efficiently in pure Python. |
Infinite Iterators
Iterator |
Argument |
Result |
Example |
count() |
start, [step] |
start, start+step, start+2*step, … |
count(10) --> 10 11 12 13 14 ... |
cycle() |
p |
p0, p1, … plast, p0, p1, … |
cycle('ABCD') --> A B C D A B C D ... |
repeat() |
elem [,n] |
elem, elem, elem, … endlessly or up to n times |
repeat(10, 3) --> 10 10 10 |
|