首页 > 解决方案 > 如何在python中拆分句子并放入列表?

问题描述

我做了一个叫做艺术家的字符串:

artist = "Kanye West and Taylor Swift"
artistName = []

我想从“和”中拆分变量并将它们附加到艺术家姓名中。

所以输出将是=['Kanye', 'West', 'Taylor', 'Swift']

标签: pythonlistsplit

解决方案


[x for x in artist.split() if x!= 'and']

推荐阅读