How to remove special characters except space from a file in python?

后端 未结 5 1531
误落风尘
误落风尘 2021-02-19 03:49

I have a huge corpus of text (line by line) and I want to remove special characters but sustain the space and structure of the string.

hello? there A-Z-R_T(,**)         


        
5条回答
  •  眼角桃花
    2021-02-19 04:13

    Create a dictionary mapping special characters to None

    d = {c:None for c in special_characters}
    

    Make a translation table using the dictionary. Read the entire text into a variable and use str.translate on the entire text.

提交回复
热议问题