I'm thinking of finding a combination using itertools in a three-dimensional array.
I would like to find the total combination of li1[i] to choose one by one.
li1 = [[0,2], [0,1,2]],
[[3]],
[[7, 9], [7,8,9],[7,6,9]],
[[11]],
[[12, 10, 20], [12, 14, 18, 20]]]
For example, if you combine the beginnings of li1[i], li1[0]→li1[1][0]→li1[2][0]→li1[3][0]li1[4][0] to [0,2,3,7,9,11,12,10,20].
result=[0, 2, 3, 7, 9, 11, 12, 10, 20], [0, 2, 3, 7, 9, 11, 14, 18, 20],
[0,2,3,7, 8, 9,11,12,10,20],[0,2,3,7, 8, 9,11,12,14,18,20],
[0,2,3,7,6,9,11,12,10,20],[0,2,3,7,6,9,11,12,14,18,20],
[0,1,2,3,7,9,11,12,10,20],[0,1,2,3,7,9,11,12,14,18,20],
[0,1,2,3,7,8,9,11,12,10,20],[0,1,2,3,7,8,9,11,12,14,18,20],
[0,1,2,3,7,6,9,11,12,10,20],[0,1,2,3,7,6,9,11,12,14,18,20]]
It doesn't matter if you don't use itertools.Thank you for your cooperation.
python
>>import intertools
>> [sum(list(l), []) for lin apply (itertools.product, li1)]
© 2024 OneMinuteCode. All rights reserved.