0

I have a list of strings:


list_of_strgs = ['if a+b > 10 and b+c < 20:',
 'if a+b > 10 ||| b+c < 20 &&b<2:',
 'x&& &&& and and x or | ||\\|| x']

In the third list, I need to replace the double backslash with a single backslash.

I tried this (see Python regex to replace double backslash with single backslash):


new = [i.replace('\\\\', '\\') for i in list_of_strgs]

This has no effect.

Any ideas what else I could try? Thanks!


3
  • 2
    if you have the text "x\\y" then you have a string that is x\y, as the text "\\" is a single backslash in the same way the text "\n" is a newline. You cannot for example do "z\\z".replace("\\", "\"). Commented Aug 12, 2021 at 21:09
  • Does this answer your question? How to replace a double backslash with a single backslash in python? Commented Aug 12, 2021 at 21:25
  • if you print out print(list_of_strgs[2]) you will get x&& &&& and and x or | ||\|| x anyway? Commented Aug 12, 2021 at 21:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.