利用re库进行正则表达替换,python3.4中
import re
a = ["123" , "456" , "789"]
d = {"B":"2","E":"5","H":"8"}
b = ",".join(a)
print (b)
for i in d.keys():
b = re.sub(d[i],i,b)
print (b.split(","))
import re
a = ["!-*%" , ".#7&33&" , "#*#71%"]
d = {"A":"#","N":"%","M":"\*"}
b = ",".join(a)
print b
for i in d.keys():
b = re.sub(d[i],i,b)
print b.split(",")
[str(j) for j in list if j]使用列表解析处理下这样的问题
假定list为 x
x = [c.replace('#','A') for c in x]
For s in list: for c in s: if c ==...这样呢?