python-3.x - 通过分隔获取列表中每个单词的计数
问题描述
我有以下列表,并想获取每个单词的计数
t_series=['Chinese, Italian, Fast Food',
'North Indian, Chinese, South Indian, Fast Food, Biryani, Street Food, Beverages',
'South Indian, North Indian, Chinese, Biryani, Street Food, Sandwich, Beverages',
'Bakery, Fast Food',
'Fast Food, Italian, Chinese, Rolls, Sandwich',
'Mithai, Street Food, Fast Food, Beverages',
'South Indian, Chinese, Street Food, Fast Food, Desserts, Beverages',
'North Indian, Chinese, South Indian, Fast Food, Desserts, Beverages',
'Fast Food, Italian, Chinese, Rolls, Sandwich',
'North Indian, South Indian',]
将字符串拆分为:-
list_sep = [st for row in t_series for st in row]
我得到的输出为: -
['C','h','i','n','e','s','e',',','','I','t','a','l ', 'i', 'a', 'n', ',',] 等等。
我希望输出为:- [Chinese, Italian, Fast Food, South Indian] 等等。
解决方案
使用者:split
_,
list_sep = [st for row in t_series for st in row.split(', ')]
print (list_sep)
['Chinese', 'Italian', 'Fast Food', 'North Indian', 'Chinese', 'South Indian',
'Fast Food', 'Biryani', 'Street Food', 'Beverages', 'South Indian', 'North Indian',
'Chinese', 'Biryani', 'Street Food', 'Sandwich', 'Beverages', 'Bakery', 'Fast Food',
'Fast Food', 'Italian', 'Chinese', 'Rolls', 'Sandwich', 'Mithai', 'Street Food',
'Fast Food', 'Beverages', 'South Indian', 'Chinese', 'Street Food', 'Fast Food',
'Desserts', 'Beverages', 'North Indian', 'Chinese', 'South Indian', 'Fast Food',
'Desserts', 'Beverages', 'Fast Food', 'Italian', 'Chinese', 'Rolls', 'Sandwich',
'North Indian', 'South Indian']
推荐阅读
- r - 将多个回归表输出到 R 中 Word 文档的多页中
- python - Exporting grid of plots as .svg in bokeh
- mysql - 从 MySQL 中的 varchar 列获取最大值
- version - Ballerina 版本 0.991.0 和 1.0.0 之间的主要区别是什么?
- jsf - 如何在jsf的渲染响应阶段生成insertAfter部分响应
- ruby-on-rails - Use sidekiq to limit request through Net::http request
- hyperledger-fabric - 如何访问 IBM Private docker 存储库
- javascript - How to customize when merge an array in Javascript
- jquery - 解析:查询类属性并按邻近度排序
- c++ - What does the ampersand do here?