More Itertools
Description:
- Additional building blocks, recipes, and routines for working with Python iterables.
Resources:
- [GitHub] https://github.com/more-itertools/more-itertools/tree/v10.1.0
- [Recipes] https://docs.python.org/3/library/itertools.html#itertools-recipes
- [Docs] https://more-itertools.readthedocs.io/en/stable/api.html
Example 1
Section titled “Example 1”Flatten a list of tuples
from more_itertools import flatten
iterable = [(0, 1), (2, 3)]list(flatten(iterable))Example 2
Section titled “Example 2”Chunk a list into a list of lists
from more_itertools import chunked
iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8]list(chunked(iterable, 3))Example 3
Section titled “Example 3”“Look ahead” at items in the iterable without advancing it
from more_itertools import spy
iterable = (x * x for x in range(1, 6))head, iterable = spy(iterable, n=3)list(head)
list(iterable)ganymede is made by Eugo