How to apply itertools.product to elements of a list of lists?

前端 未结 3 2001
迷失自我
迷失自我 2020-11-30 01:29

I have a list of arrays and I would like to get the cartesian product of the elements in the arrays.

I will use an example to make this more concrete...

iter

3条回答
  •  隐瞒了意图╮
    2020-11-30 02:08

    >>> arrays = [(-1,+1), (-2,+2), (-3,+3)]
    >>> list(itertools.product(*arrays))
    [(-1, -2, -3), (-1, -2, 3), (-1, 2, -3), (-1, 2, 3), (1, -2, -3), (1, -2, 3), (1, 2, -3), (1, 2, 3)]
    

提交回复
热议问题