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

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

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

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

問題描述

例如此列表:

[[’software’, ’foundation’], [’of’, ’the’], [’the’, ’python’], [’software’, ’foundation’],[’of’, ’the’], [’software’, ’foundation’]]# 進行頻率統(tǒng)計,例如輸出結果為:('[’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)計結果print Counter(str(i) for i in a).items() # 以列表形式返回統(tǒng)計結果# -------------- map方法 --------print Counter(map(str, a)) # 以字典形式返回統(tǒng)計結果print Counter(map(str, a)).items() # 以列表形式返回統(tǒng)計結果回答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 編程
相關文章:
主站蜘蛛池模板: 在线欧美色 | 99久久精品99999久久 | 女人张开腿让男人 | 亚洲a成人| 国产在线综合一区二区三区 | 国产精品免费综合一区视频 | 亚洲国产成人久久笫一页 | 久久精品一品道久久精品9 久久精品一区 | 国内精品久久久久不卡 | 天堂8资源在线官网资源 | 怡红院亚洲红怡院天堂麻豆 | 手机在线观看一级午夜片 | 欧美一区二区三区免费看 | 欧美精品久久天天躁 | 欧美视频一区在线 | 久久毛片久久毛 | 天堂va欧美ⅴa亚洲va一国产 | 国产91在线 | 亚洲 | 久久91亚洲精品中文字幕奶水 | 艳女伦交一级毛片 | 欧美高清一级啪啪毛片 | 成人人免费夜夜视频观看 | 久久99国产精一区二区三区! | 国产网站免费在线观看 | 女性无套免费网站在线看 | 亚洲日本高清 | 国产精品黄在线观看免费 | 精品日韩在线视频一区二区三区 | 成年视频国产免费观看 | 国产成人欧美视频在线 | 97公开免费视频 | 日韩欧美在线视频 | 91精品一区二区三区在线播放 | 日本特爽特黄特刺激大片 | 亚洲国产日韩a在线亚洲 | se就是色94欧美setu | 欧美日韩精品在线播放 | 成人网18免费网 | 国产成人综合一区精品 | 99re6这里有精品热视频在线 | 国产激情一区二区三区四区 |