Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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_Split - Fatal编程技术网

Python 把句子分开,但仍然保留分词表?

Python 把句子分开,但仍然保留分词表?,python,string,split,Python,String,Split,AXIS 2/4从AXIS活期账户转入定期贷款账户活期账户的金额 对于上面的示例,我需要如下输出: python中使用TO关键字拆分句子的一些方法 可以使用split函数拆分字符串,并将to字符串附加到最后一个元素 以下是一个片段: my_string = "AXIS 2/4 amount transferred from AXIS current account to TERM LOAN account current account" my_result = my_str

AXIS 2/4从AXIS活期账户转入定期贷款账户活期账户的金额

对于上面的示例,我需要如下输出:

python中使用TO关键字拆分句子的一些方法


可以使用split函数拆分字符串,并将to字符串附加到最后一个元素

以下是一个片段:

my_string = "AXIS 2/4 amount transferred from AXIS current account to TERM LOAN account current account"
my_result = my_string.split("to")
my_result[-1] = "to "+my_result[-1]

您不需要拆分,只需找到to的索引并获取切片即可

text=轴2/4从轴活期账户转移到定期贷款账户活期账户的金额 [text[:text.find'to'],text[text.find'to':] 输出 ['AXIS 2/4从AXIS活期账户转移至定期贷款账户活期账户的金额']
my_string = "AXIS 2/4 amount transferred from AXIS current account to TERM LOAN account current account"
my_result = my_string.split("to")
my_result[-1] = "to "+my_result[-1]