Find in python combinations of mutually exclusive sets from a list's elements

前端 未结 6 1207
我在风中等你
我在风中等你 2020-12-31 17:43

In a project I am currently working on I have implemented about 80% of what I want my program to do and I am very happy with the results.

In the remaining 20% I am f

6条回答
  •  误落风尘
    2020-12-31 18:29

    One-liner without employing the itertools package. Here's your data:

    lE={}
    lE[0]=[1, 2, 3]
    lE[1] = [3, 6, 8]
    lE[2] = [4, 9]
    lE[4] = [6, 11]
    

    Here's the one-liner:

    results=[(lE[v1],lE[v2]) for v1 in lE for v2  in lE if (set(lE[v1]).isdisjoint(set(lE[v2])) and v1>v2)]
    

提交回复
热议问题