On this page
  1. itertools.batched
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

itertools.batched

Prev: itertools.accumulate | Up: itertools | Next: itertools.chain
Rel: itertools.accumulate, itertools.chain, itertools.combinations, itertools.combinations_with_replacement
Ref: docs.python.org — itertools.batched
Tags: #public #python3 #stdlib #itertools


Import

import itertools
from itertools import batched

Signature & Overview

itertools.batched(iterable, n, *, strict=False)

Batch data into tuples of length n. The last batch may be shorter than n.

Usage

from itertools import batched

chunks = list(batched(range(7), 3))
assert chunks == [(0, 1, 2), (3, 4, 5), (6,)]

Gotchas

REPL Inspect

from itertools import batched
help(batched)

Linked from

Related notes