av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:177日期: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 編程
相關文章:
主站蜘蛛池模板: 国产成人亚洲精品自产在线 | 免费观看毛片 | 国产一区二区免费在线观看 | 99久久精品国产毛片 | 黄av在线| 午夜丁香 | 色综合av| 天天久久 | 亚洲一区国产 | 国产精品一区在线播放 | 国产a毛片| a视频在线免费观看 | 国产精品久久久久久久久久久久久 | 国产一区二区三区视频在线 | 超碰在线中文字幕 | 成人免费视屏 | 91在线一区 | 91日韩欧美 | 久久精品免费观看 | 蜜臀久久99精品久久久久久宅男 | 国产网站在线 | 久久伊人av | 长河落日| 亚洲天堂一区二区三区 | 91免费版看片 | 色日韩 | 亚洲午夜一区 | 日韩av专区 | 教室脔到她哭h粗话h好爽视频 | 久久精品一区二区三区四区 | 特一级黄色片 | 精品久久久久久久久久久久久 | 99热这里 | 91色网站| 国产在线视频网站 | 国产专区在线 | 欧美性猛交xxxx | 中国毛片视频 | 欧美 日韩 国产 成人 在线 | 成人做爰9片免费视频 | 久久精品在线观看 |