Reputation: 3
I want to find the permutation of list of list of lists For example: my input
x = [[[1,2,3],[5,6,7]],[[8,9,10],[11,12]]]
Required output should be:
[[[1,2,3],[8,9,10]],[[1,2,3],[11,12]],[[5,6,7],[8,9,10]],[[5,6,7],[11,12]]]
As you can see I want the innermost list to be intact and need to have that considered as an element and then do combinations.
I tried permutations(array) in itertools. But it didn't work.
Any help is highly appreciated.
Thank you.
Upvotes: 0
Views: 185
Reputation: 77837
You need itertools.product
import itertools
x = [[[1,2,3],[5,6,7]],[[8,9,10],[11,12]]]
for combo in itertools.product(*x):
print combo
Output:
([1, 2, 3], [8, 9, 10])
([1, 2, 3], [11, 12])
([5, 6, 7], [8, 9, 10])
([5, 6, 7], [11, 12])
Upvotes: 1