亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

python - 如何對列表中的列表進行頻率統計?

瀏覽:97日期:2022-06-30 16:46:10

問題描述

例如此列表:

[[’software’, ’foundation’], [’of’, ’the’], [’the’, ’python’], [’software’, ’foundation’],[’of’, ’the’], [’software’, ’foundation’]]# 進行頻率統計,例如輸出結果為:('[’software’,’foundation’]', 3), ('[’of’, ’the’]', 2), ('[’the’, ’python’]', 1)

問題解答

回答1:

# coding:utf8from collections import Countera = [[’software’, ’foundation’], [’of’, ’the’], [’the’, ’python’], [’software’, ’foundation’],[’of’, ’the’], [’software’, ’foundation’]]print Counter(str(i) for i in a) # 以字典形式返回統計結果print Counter(str(i) for i in a).items() # 以列表形式返回統計結果# -------------- map方法 --------print Counter(map(str, a)) # 以字典形式返回統計結果print Counter(map(str, a)).items() # 以列表形式返回統計結果回答2:

from collections import Counterdata = [[’software’, ’foundation’], [’of’, ’the’], [’the’, ’python’], [’software’, ’foundation’],[’of’, ’the’], [’software’, ’foundation’]]cnt = Counter(map(tuple, data))print(list(cnt.items()))回答3:

from itertools import groupbydata = ....print [(k, len(list(g)))for k, g in groupby(sorted(data))]

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 色 在线播放 | 国产成人一区二区三区视频免费蜜 | 一级做a爰片性色毛片思念网 | 欧美视频在线观看一区二区 | 八十老妇xxxxx性开放 | 春色精品视频在线播放 | 国产精品果冻麻豆精东天美 | 另类图片成人偷拍 | 日韩一级生活片 | 国产一区二区三区在线视频 | 国产亚洲精品高清在线 | 黄 在线| 久久香蕉影院 | 黄网站在线观看高清免费 | 国产一区美女视频 | 久久精品国产精品青草图片 | 亚洲国产精品国产自在在线 | 日韩精品一区二区三区 在线观看 | 黄网站在线播放视频免费观看 | 国产成人精品三区 | 三级免费毛片 | 国产91麻豆视频 | 久碰香蕉精品视频在线观看 | 免费在线公开视频 | 爱爱小视频免费体验区在线观看 | 国产精品一区在线麻豆 | 免费看一级欧美激情毛片 | 国产日韩欧美一区二区三区综合 | 精品国产电影网久久久久婷婷 | 日韩精品视频在线免费观看 | 国产精品videossex激情 | 欧美草逼片| 新黄色网址 | 成年黄网站免费大全毛片 | 黄色丝袜网站 | 黄网免费在线观看 | 国产在线不卡一区 | 午夜性刺激小说 | 精品精品国产高清a毛片 | 天天久久综合 | 68日本xxxxxxx18|