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

itertools.zip_longest

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


Import

import itertools
from itertools import zip_longest

Signature & Overview

itertools.zip_longest(*iterables, fillvalue=None)

Return a zip_longest object whose .next() method returns a tuple where the i-th element comes from the i-th iterable argument. The .next() method continues until the longest iterable in the argument sequence

Usage

from itertools import zip_longest

assert list(zip_longest("AB", [1, 2, 3], fillvalue=0)) == [("A", 1), ("B", 2), (0, 3)]

Gotchas

REPL Inspect

from itertools import zip_longest
help(zip_longest)

Linked from

Related notes