Itertools Permutations in Python
Level 3109 keystrokes
This generates all 2-element permutations where order matters.
Python code
# permutations() picks items where order matters1from itertools import permutations2 # Three items to arrange3items = ["A", "B", "C"]# Every ordered pair of 2 different items: 3 × 2 = 6 tuples# ("A", "B") and ("B", "A") are both included4perms = list(permutations(items, 2))# Prints [('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]5print(perms)Output
[('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
"× 6,× 3(× 3)× 3=× 2[× 1]× 1