python combinations and permutations code example
Example 1: python permutation
import itertools
a = [1, 2, 3]
n = 3
perm_iterator = itertools.permutations(a, n)
for item in perm_iterator:
print(item)
Example 2: how to get all possible combinations in python
all_combinations = [list(zip(each_permutation, list2)) for each_permutation in itertools.permutations(list1, len(list2))]
Example 3: combinations and permutations in python
from itertools import permutations
from itertools import combinations
Example 4: permutation and combination code in python
from itertools import permutations
perm = permutations([1, 2, 3], 2)
for i in list(perm):
print (i)