May-27-2018, 09:22 AM
Please put your code in the [python][/python] markers or all the indentation is lost...
Notice that your statement (the syntax highlighting does not like your profuse use of the backslash...)
Your expression works when the input has 2 or more backslashes:
Notice that your statement (the syntax highlighting does not like your profuse use of the backslash...)
>>> "\\".replace("\\\\","\\") '\\'is equivalent to:
>>> "A".replace("AA", "A") 'A'And there is obvious that in a string of 1 char there will be 0 replacements of a 2 chars group.
Your expression works when the input has 2 or more backslashes:
>>> bs = '\\' >>> s = bs * 8 >>> s '\\\\\\\\\\\\\\\\' >>> len(s) 8 >>> s.replace("\\\\", "\\") '\\\\\\\\' >>> len(_) 4