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

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

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

瀏覽:175日期: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 編程
相關文章:
主站蜘蛛池模板: 国产精品免费人成网站酒店 | 国产超碰在线观看 | 欧美在线 | 伊人网视频 | 色在线播放 | 日韩中文字幕在线观看 | 成人毛片在线观看 | 一区免费视频 | 超碰在线中文字幕 | 国产1级片| 亚洲精品18在线观看 | 天天做天天爽 | 一二三区视频 | 国产老头视频 | 久久精品一区二区三区四区五区 | 国产精品欧美在线 | 国产青青操 | 91国产丝袜在线播放 | 黄网站在线播放 | 久久久午夜精品 | 亚洲一区视频在线 | 日韩av不卡在线 | 亚洲免费一区二区 | 欧美一区二区三区在线观看 | 伦一理一级一a一片 | 成人毛片在线播放 | 国产在线小视频 | 国产又粗又猛又黄又爽无遮挡 | 久久久久久综合 | 亚洲国产一区二区三区 | 日韩成人三级 | 久视频在线 | 国产精品美女久久 | 久久综合伊人 | 国产综合视频 | 亚洲一区二区三区在线播放 | 国产又粗又大又长 | 亚洲一区二区三区视频 | 日日夜夜狠狠 | 久久久久久久免费视频 | 黄色录像免费观看 |