Pairwise Set Intersection in Python

后端 未结 3 2010
南旧
南旧 2021-02-04 06:47

If I have a variable number of sets (let\'s call the number n), which have at most m elements each, what\'s the most efficient way to calculate the pairwise in

3条回答
  •  攒了一身酷
    2021-02-04 07:29

    How about using intersection method of set. See below:

    A={"a","b","c"}
    B={"c","d","e"}
    C={"a","c","e"}
    
    intersect_AB = A.intersection(B)
    intersect_BC = B.intersection(C)
    intersect_AC = A.intersection(C)
    
    print intersect_AB, intersect_BC, intersect_AC
    

提交回复
热议问题