Answers for "compute all combinations of a list python3"

6

get all combinations from two lists python

a = ["foo", "melon"]
b = [True, False]
c = list(itertools.product(a, b))
>> [("foo", True), ("foo", False), ("melon", True), ("melon", False)]
Posted by: Guest on April-21-2020
1

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)
Posted by: Guest on December-06-2020

Code answers related to "compute all combinations of a list python3"

Python Answers by Framework

Browse Popular Code Answers by Language