Python: Permutations and Combinations
- See also Sets: Permutations and Combinations
import itertools lst = ['a', 'b', 'c'] print ("%s\n", lst); # permutations - order matters # ('a', 'b') # ('a', 'c') # ('b', 'a') # ('b', 'c') # ('c', 'a') # ('c', 'b') perm = itertools.permutations (lst, 2) for p in perm: print p # combinations - order does not matter # ('a', 'b') # ('a', 'c') # ('b', 'c') comb = itertools.combinations (lst, 2) for c in comb: print c comb =