我试图弄清楚如何做到这一点:

>>>sentence = "There's something right there."
>>>change_s(sentence)
['there', 'his', 'something', 'right', 'there.']
>>>sentence = "it's Patrick's car."
>>>change_s(sentence)
['it', 'his', 'Patrick', 'his', 'car.']


因此,基本上我想将“ s”更改为“ his”(即使在语法上不正确),并将单词放入列表中。

最佳答案

In [6]: sentence = "There's something right there."

In [7]: sentence.replace("'s", " his").split()
Out[7]: ['There', 'his', 'something', 'right', 'there.']

关于python - 改变一个词的一部分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13592174/

10-10 16:33