国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:94日期: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 編程
相關文章:
主站蜘蛛池模板: 亚洲第十色 | 国产成人免费在线观看 | 成年人毛片网站 | 最新国产午夜精品视频成人 | 亚洲视频在线免费观看 | 国产亚洲精品久久久久久久网站 | 国产精品免费一区二区三区 | 国产呦精品系列在线 | 国产精品亚洲精品不卡 | 久久成 | 亚洲精品视频久久久 | 色偷偷888欧美精品久久久 | 在线亚洲精品自拍 | 91大神大战丝袜美女在线观看 | 9l国产精品久久久久麻豆 | 亚洲成人福利在线 | 成人自拍视频网站 | 国产成人香蕉久久久久 | 国产中文字幕在线免费观看 | 一级毛片一片毛 | 99久久免费视频在线观看 | 成人午夜在线播放 | 国产精品特黄一级国产大片 | 日韩成人免费一级毛片 | 亚洲精品久久久久综合中文字幕 | 99久久香蕉 | 鲁大师成人精品视频 | 欧美一a级做爰 | 中文字幕在线观看不卡视频 | 国产成人综合精品 | 国产成人午夜精品免费视频 | 成人亚洲精品一区 | 欧美日韩精品国产一区二区 | 欧美激情国产一区在线不卡 | 国产成人免费高清激情视频 | 高清波多野结衣一区二区三区 | 成人综合在线视频 | 一级爱爱片一级毛片-一毛 一级爱做片免费观看久久 一级白嫩美女毛片免费 | 成人欧美午夜视频毛片 | 亚州免费一级毛片 | 草久网 |