亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:158日期: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 編程
相關文章:
主站蜘蛛池模板: 欧美三级在线播放 | 不卡在线观看 | 1300部小u女视频免费 | 久久精品国产2020 | 国产精品揄拍100视频最近 | 久久夜色精品 | 狠狠色狠狠色综合婷婷tag | 久久青草免费91线频观看站街 | www成人| 国产成人在线精品 | 五月天丁香婷婷网 | 黄色小视频在线免费观看 | 国产精品天仙tv在线观看 | 国产青草视频在线观看 | 亚洲欧美一级久久精品 | 亚洲第二区 | 91久色视频 | 国产欧美日韩不卡在线播放在线 | 一区二区精品在线 | 亚洲热热久久九九精品 | 99久久伊人一区二区yy5099 | 网红毛片 | 黄色短视频免费看 | 国产河南妇女毛片精品久久 | 最新露脸国产精品视频 | 国产91在线播放边 | 国产成人自拍视频在线观看 | 久操青青 | 国产精品1区2区3区在线播放 | 免费a级毛片 | 91精品免费不卡在线观看 | 97久视频精品视频在线老司机 | 善良的翁熄日本在线观看 | 日本免费专区 | 成人最新午夜免费视频 | 亚洲国产综合精品 | 正在播放avove深夜影院 | www.国产视频 | 亚洲精品久中文字幕 | 色综合久久一区二区三区 | 特黄一级黄色片 |