宝安信用卡套现,孙东,边缘人的爱与哀愁
网上看到的python去掉字符串中的标点符号的方法,大多是基于python2的,不适用python3,调整后代码如下:
代码
lower_case_documents = ['hello, how are you!','win money, win from home.','call me now.','hello, call hello you tomorrow?'] sans_punctuation_documents = [] import string for i in lower_case_documents: # todo trantab = str.maketrans({key: none for key in string.punctuation}) j = i.translate(trantab) sans_punctuation_documents.append(j) print(sans_punctuation_documents) ['hello how are you', 'win money win from home', 'call me now', 'hello call hello you tomorrow']
参考
以上这篇python3去掉string中的标点符号方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论