Home > Mobile >  Delete Tuples in List
Delete Tuples in List

Time:10-23

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!

CodePudding user response:

Try this:

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

CodePudding user response:

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

list2 = [] for i in list1: if i[0] != i[1]: list2.append(i) print(list2)

  • Related