python3去掉string中的标点符号方法
作者:kiki_kiki 时间:2021-06-27 01:29:45
网上看到的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']
参考
https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python
来源:https://blog.csdn.net/kiki_kiki/article/details/81663921
标签:python3,string,标点符号
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python分别打包出32位和64位应用程序
2023-11-03 04:41:10
![](https://img.aspxhome.com/file/2023/6/68296_0s.jpg)
利用python在大量数据文件下删除某一行的例子
2023-08-24 09:15:22
设计提升满意度
2010-05-16 15:00:00
![](https://img.aspxhome.com/file/UploadPic/20105/16/01-60s.jpg)
仿QQ和MSN消息提示的效果代码
2010-03-16 12:17:00
Response.Flush的用法
2010-04-08 12:54:00
aspjpeg组件asp代码实例使用详解
2008-12-14 10:33:00
django框架实现一次性上传多个文件功能示例【批量上传】
2022-03-30 09:00:43
![](https://img.aspxhome.com/file/2023/7/66767_0s.png)
js断点调试经验分享
2023-08-15 06:19:09
![](https://img.aspxhome.com/file/2023/7/55897_0s.png)
SQL Server跟踪数据实现索引优化向导
2009-02-13 17:14:00
![](https://img.aspxhome.com/file/UploadPic/20092/2009216122820265.jpg)
段正淳的css笔记(5)未知图片垂直居中的方法
2007-11-01 22:06:00
asp测字符串长度及截取定长字符串汉字的处理
2007-10-12 13:14:00
Python实战之markdown转pdf(包含公式转换)
2023-11-24 12:39:34
![](https://img.aspxhome.com/file/2023/8/67298_0s.png)
CSS Type set: 在线字体调整工具
2008-03-02 15:36:00
![](https://img.aspxhome.com/file/UploadPic/20083/2/csstypeset-snap_96s.gif)
用户不需要信息快餐
2009-02-25 12:34:00
浅析JavaScript对象转换成原始值
2023-08-05 02:09:11
Python 序列化 pickle/cPickle模块使用介绍
2021-04-28 17:23:21
asp中提取HTML中图片的SRC路径
2008-10-24 08:42:00
动态载入树 (ASP+数据库)
2010-05-27 12:20:00
Oracle 自增(auto increment) 或 标识字段的建立方法
2009-03-06 11:15:00
asp如何制作一个文本文件编辑器?
2010-07-07 12:26:00