Skip to content
Advertisement

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!

Advertisement

Answer

Try this:

list2 = [item for item in list1 if item[0] != item[1]]
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement