python permutation code example
Example 1: all permutations python
import itertools
print(list(itertools.permutations([1,2,3])))
Example 2: pyhton permutations
from itertools import permutations
perm = permutations([1, 2, 3])
for i in list(perm):
print (i)
Example 3: python permutation
import itertools
a = [1, 2, 3]
n = 3
perm_iterator = itertools.permutations(a, n)
for item in perm_iterator:
print(item)
Example 4: python combinations function
def combinations(iterable, r):
pool = tuple(iterable)
n = len(pool)
for indices in permutations(range(n), r):
if sorted(indices) == list(indices):
yield tuple(pool[i] for i in indices)