I would like to create a list of 3-tuples in Python. These 3-tuples should hold all possible combinations of numbers, where at least one item from each list is included. Is there any way to do this in an efficient manner?
I only thought of the possibility of nested for loops, like this:
def triplets_dos_listas(L1,L2):
triplets = []
#create list triplets
for i in range(len(L1)):
#add triplet to list triplets for all triplets with one from l1 and 2 l2
for j in range(len(L2)):
for k in range(len(L2)):
triplets += tuple([L1[i], L2[j],L2[k]])
#repeat the process for the combinations (L1,L2,L1), (L2,L1,L1) and (L2,L2,L1)
print(triplets)
However, this seems very inefficient. Also, when I try to run this, triplets is not a list of tuples but a list of single numbers, what did I do wrong there?