色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

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

問(wèn)題描述

例如此列表:

[[’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)

問(wèn)題解答

回答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)文章:
主站蜘蛛池模板: 国产日韩一区二区三区在线观看 | 色婷婷色综合激情国产日韩 | 国产亚洲女在线精品 | 九九热视频精品在线观看 | 久久精品国产一区 | 亚洲成在人线免费视频 | 成人三级网址 | 欧美一级欧美三级 | a国产| 成人ab片 | 狠狠色综合色综合网站久久 | 日韩一区二区久久久久久 | 日韩视频欧美视频 | 国产成人免费高清视频网址 | 成人国产网站 | 中国内地毛片免费高清 | 久久国产精品一区二区三区 | 无码免费一区二区三区免费播放 | 成年女人毛片 | 中文字幕在线欧美 | 亚洲天堂久久精品 | 丝袜紧身裙国产在线播放 | 国产成人综合高清在线观看 | 精品国语_高清国语自产 | 国产不卡一区二区三区免费视 | 国产欧美视频一区二区三区 | 精品免费国产一区二区三区 | 亚洲精品日韩专区在线观看 | fc2ppv在线播放 | 国产免费一区二区三区 | 久久观看| 最刺激黄a大片免费观看 | 成人在线免费观看网站 | 欧美 日韩 国产 成人 在线观看 | 黄色w站 | 中日毛片 | 日韩毛片在线免费观看 | 深夜福利视频大全在线观看 | 99久久久精品免费观看国产 | 亚洲欧美18v中文字幕高清 | 99久久久久国产精品免费 |