How to get the Cartesian product of multiple lists
Use itertools.product, which has been available since Python 2.6. import itertools somelists = [ [1, 2, 3], [‘a’, ‘b’], [4, 5] ] for element in itertools.product(*somelists): print(element) This is the same as: for element in itertools.product([1, 2, 3], [‘a’, ‘b’], [4, 5]): print(element)