简体   繁体   中英

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. Is there a method in python that can do this? I am using python 3.9.

Successful output would look like this:

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. Then use list comprehension for each web url in array.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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