Python, remove all non-alphabet chars from string

后端 未结 6 1524
时光说笑
时光说笑 2020-11-30 21:08

I am writing a python MapReduce word count program. Problem is that there are many non-alphabet chars strewn about in the data, I have found this post Stripping everything b

6条回答
  •  春和景丽
    2020-11-30 21:26

    Try:

    s = ''.join(filter(str.isalnum, s))
    

    This will take every char from the string, keep only alphanumeric ones and build a string back from them.

提交回复
热议问题