-2

I have a list of arrays

any_array = [[0,1],[1,2,3],[2,6]]

I need to get all arrays where first number is any number from [0,1], second number is from [1,2,3] and third number is from [2,6] for example [0,1,2],[1,3,6] etc How should I solve this problem in python?

michael
  • 315
  • 2
  • 9
  • Possible duplicate of [Cartesian product of x and y array points into single array of 2D points](https://stackoverflow.com/questions/11144513/cartesian-product-of-x-and-y-array-points-into-single-array-of-2d-points) – Itay Sep 16 '19 at 14:18
  • Use 3 for loops, checking if the number is in the range. – Axiumin_ Sep 16 '19 at 14:18

1 Answers1

0

This is called a cartesian product. itertools already contains a function

from itertools import product

result = []

for p in product(*x):
    result.append(list(p))
blue_note
  • 27,712
  • 9
  • 72
  • 90