import itertools as it
lang1 = {'a', 'aa'}
lang2 = {'b', 'ab'}
lang1lang2 = set([''.join(parts) for parts in it.product(lang1, lang2)])
lang2cubed = set([''.join(parts) for parts in it.product(lang2, repeat = 3)])
print("lang1lang2 = {0}".format(lang1lang2))
print("lang2cubed = {0}".format(lang2cubed))
aW1wb3J0IGl0ZXJ0b29scyBhcyBpdAoKbGFuZzEgPSB7J2EnLCAnYWEnfQpsYW5nMiA9IHsnYicsICdhYid9CgpsYW5nMWxhbmcyID0gc2V0KFsnJy5qb2luKHBhcnRzKSBmb3IgcGFydHMgaW4gaXQucHJvZHVjdChsYW5nMSwgbGFuZzIpXSkKbGFuZzJjdWJlZCA9IHNldChbJycuam9pbihwYXJ0cykgZm9yIHBhcnRzIGluIGl0LnByb2R1Y3QobGFuZzIsIHJlcGVhdCA9IDMpXSkKCnByaW50KCJsYW5nMWxhbmcyID0gezB9Ii5mb3JtYXQobGFuZzFsYW5nMikpCnByaW50KCJsYW5nMmN1YmVkID0gezB9Ii5mb3JtYXQobGFuZzJjdWJlZCkp
lang1lang2 = {'aab', 'ab', 'aaab'}
lang2cubed = {'babb', 'ababab', 'babab', 'abbab', 'bbb', 'bbab', 'abbb', 'ababb'}