找出list中的重複元素

a = [1,2,3,2,1,5,6,5,5,5]

import collections
print([item for item, count in collections.Counter(a).items() if count > 1])

輸出

[1, 2, 5]

Pycharm warning:
This inspection reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments and incorrect argument order.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章