Python
a = ['1', '2', '3', '4']
b = ['5', '6', '7', '8']
s = '1234'
将s替换为'5678'
a = ['1', '2', '3', '4']
b = ['5', '6', '7', '8']
s = '1234'
print ''.join(dict(zip(a, b)).get(c, c) for c in s)
http://www.cnblogs.com/huxi/archive/2010/12/19/1910425.html
用法很犀利
http://justpy.com/archives/177
map = string.maketrans('123', 'abc') #建立映射表,将字符串中含有的'1','2','3'替换为'a','b','c'
print '123456'.translate(map) #用创建的映射表map转换字符串
abc456
print '123456'.translate(map, '478') #用创建的映射表map转换字符串, 然后再根据后面字符串'478', 去除相同字符
abc56
http://www.keakon.net/2010/12/15/dict%E7%9A%84get%E6%96%B9%E6%B3%95%E5%BC%95%E8%B5%B7%E7%9A%84%E6%80%A7%E8%83%BD%E9%97%AE%E9%A2%98