当前位置: 移动技术网 > IT编程>脚本编程>Python > python3去掉string中的标点符号方法

python3去掉string中的标点符号方法

2019年03月21日  | 移动技术网IT编程  | 我要评论

宝安信用卡套现,孙东,边缘人的爱与哀愁

网上看到的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中的标点符号方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网