53 – Module itertools categorisation#
A good way to think about the module itertools is to remember it has five categories of iterables:
reshaping iterables:
batched,chain,groupby,islice, andpairwise;filtering iterables:
compress,dropwhile,filterfalse, andtakewhile;combinatorial iterables:
combinations,combinations_with_replacement,permutations, andproduct;infinite iterables:
count,cycle, andrepeat; andtool-complementing iterables:
accumulate,starmap, andzip_longest.
Knowing these five categories should help you remember what tools you have available.
(There’s also tee in itertools, which manipulates iterables but isn’t an iterable itself!)
Further reading:
Module
itertoolsoverview blog article.