How to remove all the escape sequences from a list of strings?

后端 未结 6 1211
南旧
南旧 2020-12-01 11:12

I want to remove all types of escape sequences from a list of strings. How can I do this? input:

[\'william\', \'short\', \'\\x80\', \'twitter\', \'\\xaa\',          


        
6条回答
  •  死守一世寂寞
    2020-12-01 12:00

    The following worked for me in Python 3.6:

    word = '\t\t\t\t\t\ntest\t msg'
    filter = ''.join([chr(i) for i in range(1, 32)])
    word.translate(str.maketrans('', '', filter))
    

    Output:

    'test msg'
    

    Source here

提交回复
热议问题