python - 使用字符串分隔符拆分字符串,并将数据与分隔符一起显示
问题描述
我需要获取字符串列表以及分隔符例如
string= "I am a developer and i need to work on web development"
我在用
re.split("and", string)```
I need to get Output as
**Output**
```I am developer
and i need to work on web development```
解决方案
尝试这个:
>>> s = "I am a developer and i need to work on web development"
>>> s1 = s.replace('and', '\nand')
>>> s1
'I am a developer \nand i need to work on web development'
>>> print(s1)
I am a developer
and i need to work on web development
>>>
推荐阅读
- python - HTTP 服务器接收文件并在 Python 中发回新文件
- javascript - 如何添加 firebase 规则以仅允许使用实时数据库访问一封用户电子邮件?
- c# - 如何在 C# 中获得与 windows Display 相同的屏幕排列?
- r - 方差分析“lm.fit(x,y,offset = offset,singular.ok =singular.ok,...)中的错误:0(非 NA)案例”
- math - 通过知道点、方向、圆位置和半径 (2D) 来查找交点
- c++ - 面向对象设计类a和子类b,如何从类一中调用类b函数
- apache-spark - 使用 pyspark 读取多个 csv 文件。只有当数据大小超过一定大小时
- pandas - 如何按值从最低到最高对空列分布进行排序
- javascript - 在初始化之前访问 JS 对象属性
- php - PHP为空col导入csv NULL