'It takes more than 1 runs to remove some values [duplicate]
I want to remove the tuples that first and second values same. But It needs more than 1 run. After 3 runs I'm getting the result that I want.
list1 = [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 2), (2, 4), (2, 6), (3, 3), (3, 6), (4, 4), (5, 5), (6, 6)]
for x,y in list1:
if x == y:
list1.remove((x,y))
Solution 1:[1]
You can use list comprehension
res = [(x, y) for x, y in list1 if x != y]
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 |
