In mathematics, when you have two sets of words A = {foo, bar} and B = {x, y}, then the algebraic product (or each of each) is AB = {foox, fooy, barx, Bary}. I would like to in Python. For two sets of words (= list of lists):
A = [ [0,1], [2,3] ]
B = [ [4,5], [6,7] ]
I would like to combine them with each other:
AB = [ [0,1,4,5], [0,1,6,7], [2,3,4,5], [2,3,6,7] ]
It is not so difficult, it can be done with product:
AB = [ a+b for (a,b) in itertools.product(A,B) ]
However, I have a list of "sets" (aka, a list of lists of lists)
A = [ [0,1], [2,3] ]
B = [ [4,5], [6,7] ]
C = [ [4,5], [6,7] ]
SETS = [A,B,C]
Now I can do it manually
ABC = [ a+b+c for (a,b,c) in itertools.product(A,B,C) ]
But I can not do this if I have 20 sets for concatenation. So, how to write a definition ABCthat will use only SETSand take any size?