为了账号安全,请及时绑定邮箱和手机立即绑定

如何从列表中删除标点符号

如何从列表中删除标点符号

侃侃无极 2021-09-28 16:19:33
我可以帮我处理这段代码吗,现在我得到的“test2”与“test”一样,如果我测试的是字符串,它运行良好,但作为列表,它无法正常工作 punc = set(string.punctuation) test=[" course content good though textbook badly written.not got energy  though seems good union.it distance course i'm sure facilities.n/an/ain last year offer poor terms academic personal. seems un become overwhelmed trying become run"]test2 = ''.join(w for w in test if w not in punc) print(test2)我想删除所有标点符号
查看完整描述

3 回答

?
qq_遁去的一_1

TA贡献1725条经验 获得超7个赞

由于 test 是一个列表,'for w in test' 将返回列表的第一项,即完整的字符串。因此,您需要访问 'w' 的所有项目以实际测试字符串的所有单个字符。


查看完整回答
反对 回复 2021-09-28
  • 3 回答
  • 0 关注
  • 230 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信