-1

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))
trgtulas
  • 37
  • 6

1 Answers1

2

You can use list comprehension

res = [(x, y) for x, y in list1 if x != y]
deadshot
  • 8,881
  • 4
  • 20
  • 39