Python3查找列表中重复元素的个数的3种方法详解


Posted in Python onFebruary 13, 2020

方法一:

mylist = [1,2,2,2,2,3,3,3,4,4,4,4]
myset = set(mylist)
for item in myset:
  print("the %d has found %d" %(item,mylist.count(item)))

the 1 has found 1

the 2 has found 4

the 3 has found 3

the 4 has found 4

方法二:

from collections import Counter
Counter([1,2,2,2,2,3,3,3,4,4,4,4])
Counter({2: 4, 4: 4, 3: 3, 1: 1})

方法三:

List=[1,2,2,2,2,3,3,3,4,4,4,4]
a = {}
for i in List:
  if List.count(i)>1:
    a[i] = List.count(i)

更多关于Python查找列表中重复元素的个数方法文章请查看下面的相关链接

Python 相关文章推荐
python paramiko模块学习分享
Aug 23 Python
使用Python实现博客上进行自动翻页
Aug 23 Python
python生成tensorflow输入输出的图像格式的方法
Feb 12 Python
用python实现k近邻算法的示例代码
Sep 06 Python
Python求两个圆的交点坐标或三个圆的交点坐标方法
Nov 07 Python
python 多线程串行和并行的实例
Feb 22 Python
2019 Python最新面试题及答案16道题
Apr 11 Python
Python机器学习算法库scikit-learn学习之决策树实现方法详解
Jul 04 Python
python的pyecharts绘制各种图表详细(附代码)
Nov 11 Python
Python pandas库中的isnull()详解
Dec 26 Python
Django 用户登陆访问限制实例 @login_required
May 13 Python
解决django migrate报错ORA-02000: missing ALWAYS keyword
Jul 02 Python
python 实现字符串下标的输出功能
Feb 13 #Python
Python3实现监控新型冠状病毒肺炎疫情的示例代码
Feb 13 #Python
python操作docx写入内容,并控制文本的字体颜色
Feb 13 #Python
使用Python 自动生成 Word 文档的教程
Feb 13 #Python
python实现替换word中的关键文字(使用通配符)
Feb 13 #Python
python isinstance函数用法详解
Feb 13 #Python
Python中的X[:,0]、X[:,1]、X[:,:,0]、X[:,:,1]、X[:,m:n]和X[:,:,m:n]
Feb 13 #Python
You might like
浅谈PHP发送HTTP请求的几种方式
2017/07/25 PHP
JavaScript和CSS通过expression实现Table居中显示
2013/06/28 Javascript
jquery实现横向图片轮播特效代码分享
2015/11/19 Javascript
JavaScript判断按钮被点击的方法
2015/12/13 Javascript
基于jQuery的网页影音播放器jPlayer的基本使用教程
2016/03/08 Javascript
使用JavaScript判断手机浏览器是横屏还是竖屏问题
2016/08/02 Javascript
微信小程序 input表单与redio及下拉列表的使用实例
2017/09/20 Javascript
nodeJS服务器的创建和重新启动的实现方法
2018/05/12 NodeJs
JS实现滑动插件
2020/01/15 Javascript
[00:53]2015国际邀请赛 中国区预选赛一触即发
2015/05/14 DOTA
Python文件和目录操作详解
2015/02/08 Python
详解supervisor使用教程
2017/11/21 Python
Python实现的redis分布式锁功能示例
2018/05/29 Python
Windows 64位下python3安装nltk模块
2018/09/19 Python
对python3中, print横向输出的方法详解
2019/01/28 Python
python plotly绘制直方图实例详解
2019/07/22 Python
利用Python校准本地时间的方法教程
2019/10/31 Python
python实现指定ip端口扫描方式
2019/12/17 Python
Python Socketserver实现FTP文件上传下载代码实例
2020/03/27 Python
Python3.9 beta2版本发布了,看看这7个新的PEP都是什么
2020/06/10 Python
前端实现弹幕效果的方法总结(包含css3和canvas的实现方式)
2018/07/12 HTML / CSS
BNKR中国官网:带你感受澳洲领先潮流时尚
2018/08/21 全球购物
一加手机美国官方网站:OnePlus美国
2019/09/19 全球购物
门卫工作岗位职责
2013/12/17 职场文书
教师队伍管理制度
2014/01/14 职场文书
出纳试用期自我鉴定
2014/04/07 职场文书
暑期教师培训方案
2014/06/07 职场文书
中秋手机店促销方案
2014/06/16 职场文书
法定代表人身份证明书(含说明)
2014/10/02 职场文书
警示教育片观后感
2015/06/17 职场文书
红白喜事主持词
2015/07/06 职场文书
采购部年度工作总结
2015/08/13 职场文书
《玩出了名堂》教学反思
2016/02/17 职场文书
竞聘书的秘诀
2019/04/02 职场文书
2019财务管理制度最新范本!
2019/07/09 职场文书
Mysql Show Profile
2021/04/05 MySQL