python - 拆分句子但仍保留分隔符?
问题描述
AXIS 2/4 金额从 AXIS 活期账户转移到 TERM LOAN 账户活期账户
对于上面的示例,我需要这样的输出:
python(使用TO关键字拆分句子的一些方法)
Output : [AXIS 2/4 amount transferred from AXIS current account] [to TERM LOAN account current account]
解决方案
您可以使用 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]
推荐阅读
- python-3.x - 如何检查某个 df['column'] 是否包含 Python 列表中的单词?
- python - 删除较大数字的最后一个数字(特定列)
- angular - Angular - 错误类型错误:无法读取未定义的属性(读取“vehicle_image”)
- django - 如何在 django 的 url 中使用没有 ID 的 PUT 操作
- r - 通过 R 中的分类变量(年份)合并子站点
- python - 输入内在调用和输入静态获取项错误
- sql - 将列写为行 (PostgreSQL)
- ios - 与重用相关的 UICollectionView 视图问题
- julia - Julia中2点之间的绘图线
- amazon-web-services - 如何使用 Amazon S3 Uri 链接下载图像?