python - 如何从 Python 中的字符串数组中删除正斜杠?
问题描述
我有一个这样的数组
arrayOne = ['["https:\/\/somewebsite.com"]','["https:\/\/anotherwebsite.com"]', '["https:\/\/lastwebsite.com"]']
本质上,我要做的是\
从上面数组中的字符串中删除正斜杠。我是python初学者,所以我边走边学。python中有没有可以做到这一点的方法?我正在使用python 3.9。
成功的输出如下所示:
arrayTwo = ['["https://somewebsite.com"]','["https://anotherwebsite.com"]', '["https://lastwebsite.com"]']
任何指导都会有所帮助!
非常感谢!
解决方案
您可以对字符串对象使用替换方法。然后对数组中的每个 web url 使用列表理解。
arrayOne = [each.replace("\\","") for each in arrayOne]
推荐阅读
- java - 如何解决减少 java 中表达式中使用的条件运算符 (5) 的数量(最多允许 3 个)的声纳问题
- mysql - 将我主机上的 MySQL 连接到我的 CentOS7 虚拟机
- javascript - 如何使脚本在 HTML 中多次运行
- parse-platform - 如何在 Android SDK - Parse Server 中更新 ParseSession?
- javascript - VanillaTilt.js 和 querySelectorAll 销毁 div 中的倾斜
- shell - 提取日志文件的信息部分并插入Oracle
- go - 如何使用 go 1.13 安装从 golang 中删除的静态内容
- python - os.system 在执行 pygame 代码时打开新窗口
- python - 在字典和列表上运行循环以检查字典值是否在列表值范围内
- .net - 使用 Superpower 解析列表列表