Efficient Way of making a set of tuple in which the order of tuple doesn't matters

  • A+

I want to make a set of tuples in which the order of tuples shouldn't matter. For eg.- If the tuples I want to add is :


It should output like this:


Is there any efficient way of doing this in python?


You can apply sorted and then tuple, followed by conversion to set:

res = set(map(tuple, map(sorted, L)))  print(res)  {(1, 2), (1, 3)} 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: