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

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

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

瀏覽:89日期: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 編程
相關文章:
主站蜘蛛池模板: 亚洲精品午夜级久久久久 | 91久久九九精品国产综合 | 清纯唯美亚洲综合 | 亚洲 欧美 国产 制服 动漫 | 国产日韩欧美综合 | 在线观看国产 | 亚洲 欧美 激情 另类 自拍 | 拍拍拍又黄又爽无挡视频免费 | 久久综合九色婷婷97 | 日本大片免a费观看视频+播放器 | 晚上睡不着偷偷看b站免费是视频 | 一区二区免费在线观看 | 黄色一级毛片免费 | 麻豆精品视频网站在线观看 | 亚洲视频一 | 亚洲欧美一区二区三区二厂 | 玖玖国产精品视频 | 欧美亚洲另类综合 | 美女国产一区 | 超清波多野结衣精品一区 | 国产成人亚洲精品老王 | 久久香蕉国产线看观看式 | 国产福利一区二区在线精品 | 成人免费国产欧美日韩你懂的 | 国产亚洲精品一区久久 | 久久久久欧美国产精品 | 亚洲一区二区日韩欧美gif | 亚洲欧美综合色区小说 | 日韩特黄特色大片免费视频 | 狠狠久久亚洲欧美专区 | 午夜国产精品影院在线观看 | 一线高清视频在线观看www国产 | 在线日本人观看成本人视频 | 曰本变态bdsm色虐七v | 香蕉视频 在线播放 | 精品一区二区三区在线视频 | 99久久综合狠狠综合久久一区 | 精品国产福利久久久 | aaa黑人一级毛片 | 青青青国产依人在在线观看高 | 成人99国产精品一级毛片 |