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

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

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

瀏覽:278日期: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 編程
相關文章:
主站蜘蛛池模板: www.色图| 日本激情网 | 欧美激情婷婷 | 中文字幕欧美在线 | av在线影院 | 欧美日韩国产一级片 | 成人在线毛片 | 欧美午夜网站 | 久久视频免费观看 | 国产天堂在线 | 亚洲区免费视频 | 色吊丝中文字幕 | a视频在线免费观看 | 国产亚洲天堂 | 日韩有码在线观看 | 天堂在线中文 | 婷婷激情四射网 | 99久精品| 日韩精品三区 | 欧美综合在线观看 | 日本一区视频在线 | 久草视频免费在线 | 中文字幕第一页在线播放 | 免费一级黄色 | 亚洲自拍偷拍精品 | 99视频在线观看免费 | 久久只有精品 | 可以在线观看av的网站 | 在线一区 | 黄色1级视频 | 超碰极品 | 特级西西444www大精品视频免费看 | 岛国av免费在线观看 | 十八女人毛片 | 亚洲一区高清 | 亚洲天堂成人在线 | 欧美久久久久久久久 | 日韩欧美高清在线 | 亚洲天堂成人在线观看 | 亚洲爽| 天天操夜夜操视频 |