1>>> import itertools
2>>> a = [[1,2,3],[4,5,6],[7,8,9,10]]
3>>> list(itertools.product(*a))
4[(1, 4, 7), (1, 4, 8), (1, 4, 9), (1, 4, 10), (1, 5, 7), (1, 5, 8), (1, 5, 9), (1, 5, 10), (1, 6, 7), (1, 6, 8), (1, 6, 9), (1, 6, 10), (2, 4, 7), (2, 4, 8), (2, 4, 9), (2, 4, 10), (2, 5, 7), (2, 5, 8), (2, 5, 9), (2, 5, 10), (2, 6, 7), (2, 6, 8), (2, 6, 9), (2, 6, 10), (3, 4, 7), (3, 4, 8), (3, 4, 9), (3, 4, 10), (3, 5, 7), (3, 5, 8), (3, 5, 9), (3, 5, 10), (3, 6, 7), (3, 6, 8), (3, 6, 9), (3, 6, 10)]
1a = ["foo", "melon"]
2b = [True, False]
3c = list(itertools.product(a, b))
4>> [("foo", True), ("foo", False), ("melon", True), ("melon", False)]
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)