Predict the output
What does this print?
from itertools import permutations
all_orders = list(permutations([1, 1, 2]))
print(len(all_orders), len(set(all_orders)))Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 6 3
Right: itertools treats the two 1s as different positions, so half the orderings repeat.
The skip rule produces the three distinct orderings directly, without building the repeated ones first.
Why not the others?
- B 3 3. permutations does not remove repeats.
- C 6 6. Swapping the two 1s gives the same tuple, which the set merges.