0

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.

3
  • How does it "not work"? It didn't work is not an adequate problem specification. Commented May 18, 2017 at 22:39
  • Hint: you aren't looking for permutations, you want the Cartesian product Commented May 18, 2017 at 22:43
  • BTW don't conflate arrays with lists. Commented May 18, 2017 at 22:45

1 Answer 1

1

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.