import itertools somelists = [ [1, 2, 3], ['a', 'b'], [4, 5] ] for element in itertools.product(*somelists): print(element)
Here is what the above code is Doing:
1. We have a list of lists, somelists.
2. We use the * operator to unpack the list of lists.
3. We pass the unpacked list of lists to itertools.product().
4. itertools.product() returns a list of tuples.
5. We iterate over the list of tuples.
6. Each tuple is printed.