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

前端 未结 3 1060
忘了有多久
忘了有多久 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:30

    You can use itertools.combinations_with_replacement().

    Return r length subsequences of elements from the input iterable allowing individual elements to be repeated more than once.

    Combinations are emitted in lexicographic sort order. So, if the input iterable is sorted, the combination tuples will be produced in sorted order.

    Elements are treated as unique based on their position, not on their value. So if the input elements are unique, the generated combinations will also be unique.

    Source: Python Docs

提交回复
热议问题