Python's itertools library is a gem - you can compose elegant solutions for a
variety of problems with the functions it provides.
In more-itertools one collect additional building blocks, recipes, and routines
for working with Python iterables.