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

我可以帮我处理这段代码吗,现在我得到的“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)

我想删除所有标点符号



侃侃无极
浏览 232回答 3
3回答

qq_遁去的一_1

由于 test 是一个列表,'for w in test' 将返回列表的第一项,即完整的字符串。因此,您需要访问 'w' 的所有项目以实际测试字符串的所有单个字符。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python