您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

2D列表中的Python计数元素频率

2D列表中的Python计数元素频率

假设我了解你想要什么,

>>> collections.Counter([x for sublist in a for x in sublist])
Counter({'mrpycharm': 3, 'its': 2, 'friends': 1, 'is': 1, 'it': 1, 'hello': 1})

要么,

>>> c = collections.Counter()
>>> for sublist in a:
...     c.update(sublist)
...
>>> c
Counter({'mrpycharm': 3, 'its': 2, 'friends': 1, 'is': 1, 'it': 1, 'hello': 1})
python 2022/1/1 18:28:19 有170人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶