I have a Python question. I have two list of lists as follows:
list_1 = [["A1","A2"],["B1","B2"],["C1","C2"]]
list_2 = [["A3","A4"],["B3","B4"],["C3"]]
I am looking for all the possible combination of these two list with only one element from each list within list. Also if the combination has only one "C" it should come from list_1 (the list which has two "C"s). For instance:
output:
[["A1","A3"],["B1","B3"],["C1","C3"]]
[["A2","A3"],["B1","B3"],["C2","C3"]]
[["A1","A4"],["B2","B3"],["C2"]]
Can this be done with the basic Python library?
Edit
This is my best try so far:
combi = []
for i in range(len(list_1)):
for j in range(len(list_1[i])):
for k in range(len(list_2[i])):
combi.extend([list_1[i][j],list_2[i][k]])
However, this did not get me what I hoped for.
question from:
https://stackoverflow.com/questions/65952742/all-the-combination-of-two-list-of-lists 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…