What is the most time efficient way to remove unordered duplicates in a 2D array?

前端 未结 3 1082
忘了有多久
忘了有多久 2021-01-12 14:08

I\'ve generated a list of combinations, using itertools and I\'m getting a result that looks like this:

nums = [-5,5,4,-3,0,0,4,-2]
x = [x for x         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-12 14:12

    Since you want to find unordered duplicates the best way to go is by typecasting. Typecast them as set. Since set only contains immutable elements. So, I made a set of tuples.

    Note: The best way to eliminate duplicates is by making a set of the given elements.

    >>> set(map(tuple,map(sorted,x)))
    {(-3, -2, 4, 5), (-5, 0, 4, 5)}
    

提交回复
热议问题