python列表--查找集合中重复元素的个数
2017-09-05 09:33
337 查看
方法一:
>>> 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)
>>> print (a)
参考资料:
http://www.jb51.net/article/53911.htm
>>> 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)
>>> print (a)
参考资料:
http://www.jb51.net/article/53911.htm
相关文章推荐
- 查找统计python列表中的重复元素
- 第二百九十八节,python操作redis缓存-Set集合类型,可以理解为不能有重复元素的列表
- [python] 查找列表中重复的元素
- python---实战日志文件中查找特定字段,文件操作读写、排序、替换、列表、集合
- 从一个集合中查找最大最小的N个元素——Python heapq 堆数据结构
- Python实现连接两个无规则列表后删除重复元素并升序排序的方法
- 对已知有限集合中缺失或重复元素的查找
- 乘号在python中的用法,用乘号将元素重复在列表中
- [python]去除列表中重复元素
- Python 去除列表中重复的元素
- 解决python list列表查找重复值的下标值问题
- python中统计列表list中的不重复元素及其相应个数
- 去除列表中不重复的元素 分类: python 小练习 2013-06-25 14:59 245人阅读 评论(0) 收藏
- Python 去除列表中重复的元素
- python小练习4:去掉列表中重复的元素
- Python 如何对含有重复列表的列表求集合?
- python求两个列表的的不同元素集合和相同元素的集合
- python中去除列表重复元素的方法汇总
- Python 去除列表中重复的元素
- Python实现判断给定列表是否有重复元素的方法