Fastest way to uniqify a list in Python

前端 未结 5 1971
感动是毒
感动是毒 2020-12-31 00:08

Fastest way to uniqify a list in Python without preserving order? I saw many complicated solutions on the Internet - could they be faster than simply:

list(s         


        
5条回答
  •  清酒与你
    2020-12-31 00:50

    This updated post by Peter Bengtsson suggests two of the fastest ways to make a list of unique items in Python 3.6+ are:

    # Unordered (hashable items)
    list(set(seq))
    
    # Order preserving
    list(dict.fromkeys(seq))
    

提交回复
热议问题