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

您的位置:首頁技術(shù)文章
文章詳情頁

python - 如何對列表中的列表進行頻率統(tǒng)計?

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

問題描述

例如此列表:

[[’software’, ’foundation’], [’of’, ’the’], [’the’, ’python’], [’software’, ’foundation’],[’of’, ’the’], [’software’, ’foundation’]]# 進行頻率統(tǒng)計,例如輸出結(jié)果為:('[’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) # 以字典形式返回統(tǒng)計結(jié)果print Counter(str(i) for i in a).items() # 以列表形式返回統(tǒng)計結(jié)果# -------------- map方法 --------print Counter(map(str, a)) # 以字典形式返回統(tǒng)計結(jié)果print Counter(map(str, a)).items() # 以列表形式返回統(tǒng)計結(jié)果回答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 編程
相關(guān)文章:
主站蜘蛛池模板: 有码视频在线 | 黄色a级| 久久青草18免费观看网站 | 美国人与性xxxxxxx | 欧美日韩国产成人高清视频 | 亚洲欧美一区二区三区在饯 | 在线中文字幕日韩 | 久久国产亚洲观看 | 亚洲综合伊人色一区 | 五月婷婷开心中文字幕 | 高清在线不卡 | 成年大片免费高清在线观看 | 国产一级毛片夜一级毛片 | 亚洲国产99在线精品一区二区 | 精品国产成人在线 | 国产老湿机福利视频在线观看 | 啪啪网址免费网址 | 国产精品第一页爽爽影院 | 国产一区中文字幕 | xxxxxxx免费| 国产成年网站v片在线观看 国产成版人视频网站免费下 | 欧美日韩综合 | 国产成人自产拍免费视频 | 日韩经典欧美精品一区 | 色两性网欧美 | 国产一区二区三区波多野吉衣 | 日本一区二区高清不卡 | 色中文在线 | 1024手机在线播放 | 一级毛片在线完整观看 | 国产chinese视频在线观看 | 欧美精品国产 | 日韩成人在线观看视频 | 亚洲美女在线观看亚洲美女 | 精品一区二区三区自拍图片区 | 99综合精品久久 | 欧美在线观看一区二区 | 九九精品国产99精品 | 亚州综合激情另类久久久 | 亚洲最大综合网 | 麻豆视频网站在线观看 |