Remove backslash with str.translate
Question: I wrote the following Python2.7 code to remove digits and the backslash
character (\\) from some string. I attempted to use the str.translate method,
because I had learned that it is very efficient. The code below successfully
removed digits from the string x, but is unable to remove the single backslash
in y. What did I do wrong?

    
    
    import string    
    x = 'xb7'
    y = '\xb7'
    print x.translate(None, '\\' + string.digits)
    print y.translate(None, '\\' + string.digits)
    


Answer: You don't have any strings with backslashes. `x` has the characters `'x'`,
`'b'`, and `'7'`, while `y` has a single character, `'·'`, denoted by the hex
code `b7`. If you want the literal string `'\xb7'`, with four characters in
it, use a raw string by prefixing an `r` in front of the literal.

    
    
    >>> import string
    >>> print r'\xb7'.translate(None, '\\' + string.digits)
    xb
    

