Python 把句子分开,但仍然保留分词表?
AXIS 2/4从AXIS活期账户转入定期贷款账户活期账户的金额 对于上面的示例,我需要如下输出: python中使用TO关键字拆分句子的一些方法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
可以使用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]