Best way to strip punctuation from a string

前端 未结 26 1885
日久生厌
日久生厌 2020-11-21 05:39

It seems like there should be a simpler way than:

import string
s = \"string. With. Punctuation?\" # Sample string 
out = s.translate(string.maketrans(\"\",\         


        
26条回答
  •  不思量自难忘°
    2020-11-21 06:15

    This might not be the best solution however this is how I did it.

    import string
    f = lambda x: ''.join([i for i in x if i not in string.punctuation])
    

提交回复
热议问题