0

How do I find combos of a list of lists of lists? Here is an example below.

My list of lists of lists (where the 1st sublist can contain a single list or multiple lists):

[[5,6],[[2,4],[5,7]],[1,8],[[-1,-2],[1,0]]]

This what I want to get:

[5,6],[2,4],[1,8],[-1,-2]    
[5,6],[2,4],[1,8],[1,0]
[5,6],[5,7],[1,8],[-1,-2]
[5,6],[5,7],[1,8],[1,0]

Basically looking for the combos for that 2nd level list. I believe it's possible using the itertools lib but unsure how to use it.

steve9120
  • 19
  • 2
  • 2
    `product([[5,6]], [[2,4],[5,7]], [[1, 8]], [[-1,-2],[1,0]])`. – Martijn Pieters Apr 10 '17 at 19:52
  • I'm only looking for the combinations of the 2nd level list, not the "product." – steve9120 Apr 10 '17 at 19:57
  • Did you even try to run that line? Yes, you want a product of the nested lists, your only mistake is not to put the single element lists into a list of their own. – Martijn Pieters Apr 10 '17 at 20:00
  • Try out the code in the first comment. I believe that you will find that it does what you want, at least approximately (using tuple rather than lists). The words `product` and `combination` have technical meanings here, and apparently you really are asking for a Cartesian product, not for combinations. – Rory Daulton Apr 10 '17 at 20:01
  • @RoryDaulton: I ran `for c in product([[5,6]], [[2,4],[5,7]], [[1, 8]], [[-1,-2],[1,0]]): print(*c)`, that produces the expected output by unpacking the tuple. – Martijn Pieters Apr 10 '17 at 20:02
  • @MartijnPieters It is not possible to answer this question? – Dalek Apr 10 '17 at 21:13
  • @MartijnPieters I guess the answer is not like only using `product` function from `itertools`. – Dalek Apr 10 '17 at 21:39

0 Answers0