如何找出Python list中有重复的项?

如何找出Python list中有重复的项


手掌心
浏览 1224回答 1
1回答

米琪卡哇伊

1subl=[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 linuxType "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}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python