Permutations between two lists of unequal length
The simplest way is to use itertools.product: a = [“foo”, “melon”] b = [True, False] c = list(itertools.product(a, b)) >> [(“foo”, True), (“foo”, False), (“melon”, True), (“melon”, False)]
The simplest way is to use itertools.product: a = [“foo”, “melon”] b = [True, False] c = list(itertools.product(a, b)) >> [(“foo”, True), (“foo”, False), (“melon”, True), (“melon”, False)]
Use itertools.permutations from the standard library: import itertools list(itertools.permutations([1, 2, 3])) Adapted from here is a demonstration of how itertools.permutations might be implemented: def permutations(elements): if len(elements) <= 1: yield elements return for perm in permutations(elements[1:]): for i in range(len(elements)): # nb elements[0:1] works in both string and list contexts yield perm[:i] + elements[0:1] + … Read more