午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:286日期: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精品国产高清一区二区三蜜臀 | 日韩视频在线观看一区二区 | 国产精品五月天 | 69福利视频 | 欧美日韩在线观看成人 | 丁香六月激情综合 | 成人午夜高清 | 四虎成人免费 | 韩国三级中文字幕hd久久精品 | 欧美在线一级 | 日韩av手机在线观看 | 综合成人在线 | 成人性生活毛片 | 日日骚网 | 一起草av在线 | 午夜在线看片 | 国产精品自拍一区 | 69老司机| 国产精品suv一区二区 | 在线免费观看国产视频 | 亚洲精品aa| 夜夜骑天天操 | 亚洲网站在线 | 午夜精品小视频 | 亚洲成年人在线观看 | 中文字幕精品视频在线观看 | 国产久草视频 | 日本一区二区高清视频 | 超碰碰97| 四虎8848精品成人免费网站 | 成人高清网站 | 久久黄网 | 性做久久久| 久久91久久 | 婷婷丁香色| 精品视频区 | 黄色一级视频免费看 | 五月天综合在线 |