如何找出Python list中有重复的项
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}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询