Is there an algorithm to find unique combinations of 2 lists? 5 lists?

后端 未结 7 2435
醉话见心
醉话见心 2020-12-20 06:29

I have N Lists I\'d like to find unique combinations of. I\'ve written it out on my whiteboard and it all seems to have a pattern, I just haven\'t found it

7条回答
  •  情话喂你
    2020-12-20 06:53

    You're looking for the Cartesian product. In Python, if you want tuples:

    c = [(x, y) for x in a for y in b]
    r = [(vv, ww, xx, yy, zz)
         for vv in v  for ww in w  for xx in x  for yy in y  for zz in z]
    

提交回复
热议问题