码迷,mamicode.com
首页 > 其他好文 > 详细

删除字符串中的字符列表

时间:2019-10-23 18:01:07      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:www   tool   too   tps   klist   list   lam   iter   python   

问题
我想在python中删除字符串中的字符:

string.replace(',', '').replace("!", '').replace(":", '').replace(";", '')...

但是我必须删除许多字符。 我想到了一个清单

list = [',', '!', '.', ';'...]

但是如何使用list替换string中的字符?

方法一

import more_itertools as mit
s = "A.B!C?D_E@F#"
blacklist = ".!?_@#"
s="".join(mit.flatten(mit.split_at(s, pred=lambda x: x in set(blacklist))))
print(s)

from: https://www.itranslater.com/qa/details/2115759020177884160

删除字符串中的字符列表

标签:www   tool   too   tps   klist   list   lam   iter   python   

原文地址:https://www.cnblogs.com/hankleo/p/11727609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!