Fastest way to get sorted unique list in python?

后端 未结 5 2022
谎友^
谎友^ 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:54

    >>> import itertools
    >>> a=[2,3,4,1,2,7,8,3]
    >>> list(k for k,_ in itertools.groupby(sorted(a)))
    [1, 2, 3, 4, 7, 8]
    

提交回复
热议问题