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

itertools.permutations

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


Import

import itertools
from itertools import permutations

Signature & Overview

itertools.permutations(iterable, r=None)

Return successive r-length permutations of elements in the iterable.

Usage

from itertools import permutations

assert list(permutations("AB")) == [("A", "B"), ("B", "A")]
assert list(permutations([1, 2, 3], 2)) == [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]

Gotchas

REPL Inspect

from itertools import permutations
help(permutations)

Linked from

Related notes