Split Strings into words with multiple word boundary delimiters

前端 未结 30 2626
既然无缘
既然无缘 2020-11-21 05:09

I think what I want to do is a fairly common task but I\'ve found no reference on the web. I have text with punctuation, and I want a list of the words.

\"H         


        
30条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-21 05:47

    using maketrans and translate you can do it easily and neatly

    import string
    specials = ',.!?:;"()<>[]#$=-/'
    trans = string.maketrans(specials, ' '*len(specials))
    body = body.translate(trans)
    words = body.strip().split()
    

提交回复
热议问题