Content · Programming · Python

Python itertools.permutations() Function: Usage and Examples

Generate ordered arrangements without replacement.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Generate ordered arrangements without replacement.

What You Will Learn


permutations(iterable, r=None) selects r positions from the input; input elements are treated as distinct by position, even if values repeat.

For floating-point results, remember that stored values are approximations. Rounding a displayed value does not change the exact value used by later calculations.

Step-by-Step Example


The example below makes the behavior visible with small input values that you can change safely.

from itertools import permutations
print(list(permutations("ABC", 2)))

How the Example Works


  • The imports provide the standard-library tools used in the demonstration: itertools.
  • The print() calls make the return values or state visible so you can compare them with the explanation and check your prediction.

For the chosen input, the expression list(permutations('ABC', 2)) prints [('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]. Compare that result with the rule above before you change the argument.

Expected output from the example:

[('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]

Another Example: Compare the Results


Try a second input and compare it with the first. Notice whether the result changes in type, value, order, or number of items.

from itertools import permutations
print(list(permutations("ABC", 2)))

Expected output:

[('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]

When You Would Use This


This operation can support measurements, numeric reports, simulations, or input validation. Choose integer operations when exact integer answers are required, and check floating-point rounding when displaying measured values. Validate units and input domains before using the result in a calculation.

Practice: Modify the Code


Produce possible presentation orders for three speakers.

Verify the changed output against the behavior described above, including the relevant invalid or boundary case.

For complete parameters and version details, consult the official Python documentation.

Common Beginner Mistakes


  • Treating permutations as unordered selections or overlooking factorial growth.
  • Consuming a one-pass iterator during an earlier check and assuming the same values remain available.

Key Takeaways


  • Generate ordered arrangements without replacement.
  • permutations(iterable, r=None) selects r positions from the input; input elements are treated as distinct by position, even if values repeat.
  • Apply this operation only after checking the assumptions and input conditions shown in the example.
Share this resourceSend this page to someone who may find it useful.