如何找出Python list中有重復的項
1 回答

米琪卡哇伊
TA貢獻1998條經(jīng)驗 獲得超6個贊
1 | subl = [i for i in l if l.count(i)> 1 ] |
Python 3.5.2 (default, Sep 30 2016, 01:32:24)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> l=[2,2,3,4,5,6,7,7,7,7]
>>> subl=[i for i in l if l.count(i)>1]
>>> subl
[2, 2, 7, 7, 7, 7]
>>> set(subl)
{2, 7}
添加回答
舉報
0/150
提交
取消