【发布时间】:2019-05-05 00:20:56
【问题描述】:
我有一个字符串和一个列表:
src = 'ways to learn are read and execute.'
temp = ['ways to','are','and']
我想要的是使用列表temp 的值拆分字符串并生成:
['learn','read','execute']
同时。
我试过for循环:
for x in temp:
src.split(x)
这是它产生的:
['','to learn are read and execute.']
['ways to learn','read and execute.']
['ways to learn are read','execute.']
我想要的是先输出列表中的所有值,然后用它拆分字符串。
有人有解决办法吗?
【问题讨论】:
-
为什么所需的输出在
'execute'的末尾不包含一个点? -
@timgeb 感谢提醒,其实点也不是我想要的。我忘了指定。
标签: python string python-3.x split