python - 在字符串的特定位置插入字符
问题描述
我有以下问题。我想在特定列的以下字符串中的每个“)”之后插入“,”。
The Bahamas (All locations)Bermuda (All locatins)Romania (Cluj)Bulgaria (All locations)
这个想法是我在同一个表的同一列的多行上都有这种类型的字符串。请在这个问题上帮助我。
我希望有:
The Bahamas (All locations),Bermuda (All locatins),Romania (Cluj),Bulgaria (All locations),
为了以我需要的信息的方式进行拆分。
解决方案
使用 str.replace():
In [1]: s1 = 'The Bahamas (All locations)Bermuda (All locatins)Romania (Cluj)Bulgaria (All locations)'
In [2]: s2 = s1.replace(')', '),')
In [3]: s2
Out[3]: 'The Bahamas (All locations),Bermuda (All locatins),Romania (Cluj),Bulgaria (All locations),'
推荐阅读
- gitlab - 如何在 gitlab 中推送到新创建的项目
- c++ - 读取 UNICODE_STRING 的缓冲区时访问冲突
- java - Swagger API 中声明为不需要的 QueryParam
- php - 警告:mysqli_fetch_row() 期望参数 1 为 mysqli_result,给定 null
- php - 如何在 URL 中添加参数以在同一页面上显示不同的内容?
- visual-studio-app-center - Xamarin UItest 是否支持本地?还是现在只适用于应用中心?
- python - Scrapy:meta['proxy'] 还是 meta['proxy']?
- grid - Extjs 可编辑网格将行推开
- python-3.7 - sys.executable 的 Python 3.7 无法识别的字符
- reactjs - lodash 的 isEqual 是提高 shouldComponentUpdate 性能的可行方法吗?