Combine tuples in a list which have the same value [duplicate]
问题 This question already has answers here : Union find implementation using Python (4 answers) Find the intersection between sublists (2 answers) Finding common elements in list in python (4 answers) Closed 4 years ago . I have a list with tuples like this: L ={(1,2), (1,4), (1,3), (2,3), (3,4), (3,5), (4,5), (6,7)} I try to combine these to get equivalence classes (tuples of the same value are merged, like (1,2) and (2,3) becomes (1,2,3)). So you get: EQ = {(1,2,3,4,5), (6,7)} What's the