import itertools
somelists = [
[1, 2, 3],
['a', 'b'],
[4, 5]
]
for element in itertools.product(*somelists):
print(element)
# initialize lists
listA = [1, 4, 6, 7]
listB = [1, 3]
# Construct Cartesian Product Tuple list
# using list comprehension
res = [(a, b) for a in listA for b in listB]
# printing result
print("The Cartesian Product is : " + str(res))