All combinations of a list of lists

后端 未结 7 1605
离开以前
离开以前 2020-11-22 00:38

I\'m basically looking for a python version of Combination of List>

Given a list of lists, I need a new list that gives all the possible combin

7条回答
  •  我寻月下人不归
    2020-11-22 00:55

    Numpy can do it:

     >>> import numpy
     >>> a = [[1,2,3],[4,5,6],[7,8,9,10]]
     >>> [list(x) for x in numpy.array(numpy.meshgrid(*a)).T.reshape(-1,len(a))]
    [[ 1, 4, 7], [1, 5, 7], [1, 6, 7], ....]
    

提交回复
热议问题