Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想修剪列表
[0,0,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3, ... , 145,145,145]
进入
[0,1,2,3,4,...,145]
我知道在 Python 中使用“C 编程风格”的方式。
我在这里要求一种智能和聪明的方式来做到这一点。
numpy.unique(mylist)或者list(set(mylist))应该做。
numpy.unique(mylist)
list(set(mylist))
PS这不是“修剪”-那是另一回事...
使用set:
set
unique = [x for x in set(original)]
或者
unique = list(set(original))
试试这个
print list(set(my_list))