9
Itertools for Combinatorics – Permutations and Combinations
Functional programming emphasizes stateless algorithms. In Python, this leads us to work with generator expressions, generator functions, and iterables. In this chapter, we’ll continue our study of the itertools
library, with numerous functions to help us work with iterable collections.
In the previous chapter, we looked at three broad groupings of iterator functions. They are as follows:
Functions that work with infinite iterators, which can be applied to any iterable or an iterator over any collection; they consume the entire source
Functions that work with finite iterators, which can either accumulate a source multiple times, or produce a reduction of the source
The
tee()
iterator function, which clones an iterator into several copies that can each be used independently
In this chapter, we’ll look at the itertools
functions that work with permutations and combinations. These include several combinatorial...