Python 改变一个词的一部分
我正试图找出如何做到这一点:Python 改变一个词的一部分,python,string,list,Python,String,List,我正试图找出如何做到这一点: >>>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'
>>>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”(即使语法上不正确),并将单词列在一个列表中。@IgnacioVazquez Abrams:这是漫长的一天,谢谢你的建议。@IgnacioVazquez Abrams:这是漫长的一天,谢谢你的建议。你知道“这是他的”!=“是的”,对吧?你知道“是他的”!=“是的”,对吧?
In [6]: sentence = "There's something right there."
In [7]: sentence.replace("'s", " his").split()
Out[7]: ['There', 'his', 'something', 'right', 'there.']