Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 改变一个词的一部分_Python_String_List - Fatal编程技术网

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.']