What is the cleanest way to do a sort plus uniq on a Python list?

后端 未结 5 936
囚心锁ツ
囚心锁ツ 2020-12-23 15:55

Consider a Python list my_list containing [\'foo\', \'foo\', \'bar\'].

What is the most Pythonic way to uniquify and sort a list ?
(thi

5条回答
  •  感情败类
    2020-12-23 16:25

    Can't say it is clean way to do that, but just for fun:

    my_list = [x for x in sorted(my_list) if not x in locals()["_[1]"]]
    

提交回复
热议问题