'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)
Solution 1:[1]
for elm in your_tuple:
if elm[0] == elm[2] == elm[3] != elm[5]:
print(elm)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | magimix |
