Search code examples
pythonlistlist-comprehension

Delete Tuples in List


i want to delete Tuples out of a list if they have the same number...

list1 = [(0, 2), (0, 3), (25, 25), (0, 9), (26, 26), (27, 27)]

and I need

list2 = [(0, 2), (0, 3), (0, 9)]

Thanks a lot!


Solution

  • Try this:

    list2 = [item for item in list1 if item[0] != item[1]]