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

时间:2014-06-23 06:41:24   收藏:0   阅读:214

如果一个Python list中有很多重复的项,如何有效地找到多少重复的项呢?

 

可以使用collection的Counter方法。。

>>> from collections import Counter
>>> Counter([11,22,11,44,22,33])
Counter({11: 2, 22: 2, 33: 1, 44: 1})

  

[Python Tips]如何找出Python list中有重复的项,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!