Getting unique tuples from a list [duplicate]
问题 This question already has answers here : Getting unique tuples out of a python set (4 answers) Closed 2 years ago . I have a list of tuples whose elements are like this: aa = [('a', 'b'), ('c', 'd'), ('b', 'a')] I want to treat ('a', 'b') and ('b', 'a') as the same group and want to extract only unique tuples. So the output should be like this: [('a', 'b'), ('c', 'd')] How can I achieve this efficiently as my list consists of millions of such tuples? 回答1: Convert to a frozenset , hash, and