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!


Son
  • 159
  • 1
  • 11
  • 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("\\", "\")`. – JonSG Aug 12 '21 at 21:09
  • Does this answer your question? [How to replace a double backslash with a single backslash in python?](https://stackoverflow.com/questions/6752485/how-to-replace-a-double-backslash-with-a-single-backslash-in-python) – Brad Solomon Aug 12 '21 at 21:25
  • if you print out ``print(list_of_strgs[2])`` you will get ``x&& &&& and and x or | ||\|| x`` anyway? – Karina Aug 12 '21 at 21:39

0 Answers0