简体   繁体   English

如何从 Python 中的字符串数组中删除正斜杠?

[英]How can I remove forward slash(es) from an array of strings in Python?

I have an array as such我有一个这样的数组

arrayOne = ['["https:\/\/somewebsite.com"]','["https:\/\/anotherwebsite.com"]', '["https:\/\/lastwebsite.com"]']

Essentially, what I am trying to do is remove the forward slash \ from the strings in the array above.本质上,我要做的是从上面数组中的字符串中删除正斜杠\ I am a python beginner so I am learning as I go.我是 python 初学者,所以我正在学习 go。 Is there a method in python that can do this? python 中是否有可以做到这一点的方法? I am using python 3.9.我正在使用 python 3.9。

Successful output would look like this:成功的 output 如下所示:

arrayTwo = ['["https://somewebsite.com"]','["https://anotherwebsite.com"]', '["https://lastwebsite.com"]']

Any guidance would be helpful!任何指导都会有所帮助!

Thank you very much!非常感谢!

You can use replace method for string object.您可以对字符串 object 使用替换方法。 Then use list comprehension for each web url in array.然后对数组中的每个 web url 使用列表理解。

arrayOne = [each.replace("\\","") for each in arrayOne]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM