combination of elements python code example
Example 1: python get all combinations of list
itertools.combinations(iterable, r)
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: how to find a combination of all elements in a python list
import itertools
stuff = [1, 2, 3]
for L in range(0, len(stuff)+1):
for subset in itertools.combinations(stuff, L):
print(subset)