How to remove duplicates from a list of tuples irrespective of order in Python

2 Answers

0 votes
tuplelist = [(4, 5), (5, 4), (1, 3), (3, 1), (8, 9), (2, 4)]

tuplelist = list(set(map(tuple, map(sorted, tuplelist))))

print(tuplelist)




'''
run:

[(4, 5), (8, 9), (1, 3), (2, 4)]

'''

 



answered Dec 2, 2022 by avibootz
0 votes
tuplelist = [(4, 5), (5, 4), (1, 3), (3, 1), (8, 9), (2, 4)]

tuplelist = [tuple(sorted(val)) for val in tuplelist]
tuplelist = list(set(tuplelist))

print(tuplelist)




'''
run:

[(4, 5), (8, 9), (1, 3), (2, 4)]

'''

 



answered Dec 2, 2022 by avibootz
...