Fastest way to get sorted unique list in python?

后端 未结 5 2016
谎友^
谎友^ 2021-02-01 06:16

What is the fasted way to get a sorted, unique list in python? (I have a list of hashable things, and want to have something I can iterate over - doesn\'t matter whether the lis

5条回答
  •  离开以前
    2021-02-01 06:56

    import numpy as np
    np.unique(...)
    

    The np.unique function returns an ndarray unique and sorted based on an array-like parameter. This will work with any numpy types, but also regular python values that are orderable.

    If you need a regular python list, use np.unique(...).tolist()

提交回复
热议问题