Removing Punctuation From Python List Items

后端 未结 5 711
耶瑟儿~
耶瑟儿~ 2020-11-29 08:56

I have a list like

[\'hello\', \'...\', \'h3.a\', \'ds4,\']

this should turn into

[\'hello\', \'h3a\', \'ds4\']

5条回答
  •  伪装坚强ぢ
    2020-11-29 09:27

    In python 3+ use this instead:

    import string
    s = s.translate(str.maketrans('','',string.punctuation))
    

提交回复
热议问题