>>> import itertools
>>> perms = itertools.permutations(['r','e','d'])
>>> perms
>>> list(perms)
[('r', 'e', 'd'), ('r', 'd', 'e'), ('e', 'r', 'd'), ('e', 'd', 'r'), ('d', 'r', 'e'), ('d', 'e', 'r')]
>>>
import itertools
print (list(itertools.permutations(['a','d','e','g'])))
参考:
>>> import itertools
>>> itertools.combinations(range(10), 5)
>>> [_ for _ in itertools.combinations(range(10), 5)]
[(0, 1, 2, 3, 4), (0, 1, 2, 3, 5), (0, 1, 2, 3, 6), (0, 1, 2, 3, 7), (0, 1, 2, 3, 8), (0, 1, 2, 3, 9), (0, 1, 2, 4, 5), (0, 1, 2, 4, 6), (0, 1, 2, 4, 7), (0, 1, 2, 4, 8), (0, 1, 2, 4, 9), (0, 1, 2, 5, 6), (0, 1, 2 ... ) ... ]