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

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

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

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

問題描述

例如此列表:

[[’software’, ’foundation’], [’of’, ’the’], [’the’, ’python’], [’software’, ’foundation’],[’of’, ’the’], [’software’, ’foundation’]]# 進(jìn)行頻率統(tǒng)計(jì),例如輸出結(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)計(jì)結(jié)果print Counter(str(i) for i in a).items() # 以列表形式返回統(tǒng)計(jì)結(jié)果# -------------- map方法 --------print Counter(map(str, a)) # 以字典形式返回統(tǒng)計(jì)結(jié)果print Counter(map(str, a)).items() # 以列表形式返回統(tǒng)計(jì)結(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))]

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 久久精品欧美一区二区三区不卡 | 五月婷婷中文 | 影音先锋男 | 日韩视频三区 | 香蕉91| 日韩精品视频一区二区三区 | 久久99精品久久久久久国产越南 | 九九国产在线观看 | 国产亚洲一区二区精品 | 黑人精品 | 午夜精品一区二区三区在线视频 | 欧美xxxx网站 | 一区欧美 | 国产一二区视频 | 97精品国产 | 欧美日韩一区在线观看 | 成人做爰999| 午夜天堂精品久久久久 | 久久久五月天 | 天天草天天操 | 亚洲国产免费 | 久久久久国产一区二区三区 | 亚洲第一视频网站 | 国产精品污污视频 | 日韩精品一区二区三区免费视频 | 亚洲视频免费观看 | 成人毛片网 | 伊人啪啪网 | 日韩一区二区在线视频 | 欧美视频一区二区三区 | 国产毛片视频 | 91影院在线观看 | 国产在线视频在线观看 | 天天干天天爽 | 麻豆精品一区二区三区在线观看 | 在线播放91 | 国产精品日韩欧美 | 99久久精品免费看国产四区 | 日韩电影在线 | 2018国产精品 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 |