如何使用RegEx(或者Python中的其他东西)满足以下需求? 我需要:
输入:
text = ["Dream of a car",
"Dream to live in a world",
"Dream about 8am every morning",
"stopped dreaming today",
"still dreaming of a car",
"One more dream to come late tomorrow",
"Dream coming to hope tomorrow"]
所需输出:
["a car",
"live in a world",
"8am every morning",
" ",
"a car",
"come late tomorrow",
"hope tomorrow"]
我试过:
result = [re.sub('Dream', '', a) for a in text]
# MyOutput
[' of a car', ' to live in a world', ' about 8am every morning', 'stopped dreaming today', 'still dreaming of a car', 'One more dream to come late tomorrow', ' coming to hope tomorrow']
这将提供所需的输出
如果你只想移除前面的to
相关问题 更多 >
编程相关推荐