zarek37
zarek37

Reputation: 47

tuples in a list finding common elements

Let's assume I have a list that can contain a number of tuples (it will vary), such as:

[(ele1, ele2, ele3, ele4, elle5, ele6, ele7),
(ele1, ele2, ele3, ele4, elle5, ele6, ele7),
(ele1, ele2, ele3, ele4, elle5, ele6, ele7),
(ele1, ele2, ele3, ele4, elle5, ele6, ele7),
(ele1, ele2, ele3, ele4, elle5, ele6, ele7),
etc..]

I want to find the tuples where ele1, ele3, ele4 are the same but ele6 is different)

Upvotes: 1

Views: 137

Answers (1)

magimix
magimix

Reputation: 187

for elm in your_tuple:
        if elm[0] == elm[2] == elm[3] != elm[5]: 
            print(elm)

Upvotes: 1

Related Questions