我有一個巨大的文本語料庫(逐行),我想刪除特殊字符但支持字符串的空間和結構。如何從python文件中除去空格以外的特殊字符?
hello? there A-Z-R_T(,**), world, welcome to python.
this **should? the next line#followed- [email protected] an#other %million^ %%like $this.
應該
hello there A Z R T world welcome to python
this should be the next line followed by another million like this
只需創建您想要的字符列表,AZ,az,0-9等。然後使用for循環遍歷字符串中的每個字符,用空格替換不在列表中的字符。 – Wright
對於數百萬行文本的巨大語料庫是否有效? – pythonlearn