1import itertools
2
3a = [1, 2, 3]
4n = 3
5
6perm_iterator = itertools.permutations(a, n)
7
8for item in perm_iterator:
9 print(item)
1def combinations(iterable, r):
2 pool = tuple(iterable)
3 n = len(pool)
4 for indices in permutations(range(n), r):
5 if sorted(indices) == list(indices):
6 yield tuple(pool[i] for i in indices)