python - 如何在python中拆分句子并放入列表?
问题描述
我做了一个叫做艺术家的字符串:
artist = "Kanye West and Taylor Swift"
artistName = []
我想从“和”中拆分变量并将它们附加到艺术家姓名中。
所以输出将是=['Kanye', 'West', 'Taylor', 'Swift']
解决方案
[x for x in artist.split() if x!= 'and']
推荐阅读
- web-scraping - 如何解释这个 robots.txt 文件?
- javascript - 重新加载父窗口
- python - IBM DSX 本地:ImportError:没有名为 project_lib 的模块
- android - 如果“高度”设置为 2dp 或低于“wrap_content”,SeekBar 不显示完整的“拇指图标”
- java - 使用 hamcrest 的 Assert.fail 等效项
- .net-standard - 确定当前运行的框架的上下文
- html - 圆圈分为六个部分
- spring-integration - 成功通道后删除文件
- visual-studio - 使用 React 组件防止 Visual Studio JSX 行为
- javascript - Consume multiple topics in a single consumer on kafka