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

itertools.count

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


Import

import itertools
from itertools import count

Signature & Overview

itertools.count(start=0, step=1)

Return a count object whose .next() method returns consecutive values.

Usage

from itertools import count, islice

assert list(islice(count(start=10, step=5), 4)) == [10, 15, 20, 25]
# Handy with zip() to attach custom starting indices
assert list(zip(count(1), ["a", "b"])) == [(1, "a"), (2, "b")]

Gotchas

REPL Inspect

from itertools import count
help(count)

Linked from

Related notes