Generation of Combinatorial Objects · Generating Permutations
Lesson 2
In Python, there are generators for permutations of fixed length \(k\). The code below generates all such permutations of length \(k=2\).
from itertools import permutations
for p in permutations('abc', 2):
print(*p, sep='', end=' ')ab ac ba bc ca cb
In particular, when \(k\) equals the size of the set, it simply enumerates all permutations. abc acb bac bca cab cba