Skip to content

Description:

  • Additional building blocks, recipes, and routines for working with Python iterables.

Resources:

Flatten a list of tuples

from more_itertools import flatten
iterable = [(0, 1), (2, 3)]
list(flatten(iterable))

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))

“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