Skip to content
UPEEC

itertools

Fast iterator building blocks: count, cycle, chain, product, permutations, combinations, groupby, accumulate, islice, pairwise and more.

Intermediate
Comments 0
from itertools import product, combinations, accumulate, groupby, pairwise, islice
list(product("AB", repeat=2))        # AA AB BA BB
list(combinations([1, 2, 3], 2))     # (1,2) (1,3) (2,3)
list(accumulate([1, 2, 3]))          # running totals 1 3 6
list(pairwise([1, 4, 9]))            # (1,4) (4,9)

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.