如何找出Python list中有重复的项
1 回答
![?](http://img1.sycdn.imooc.com/54585050000156a302200220-100-100.jpg)
米琪卡哇伊
TA贡献1998条经验 获得超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
提交
取消