Hello其他程序员:) 只是一个简单的问题
假设我正在加密文字。
我有“a,b,c,d,e”的阴影字符,分别是“w,p,z,r,a”
original =["a","b","c","d","e"]
shadow = ["w","p","z","r","a"]
然后,如果用户输入字符串
user = input("What would you like to input?: ")
假设用户输入一个字符串“坏的驾驶室床”
如何让它用字符串替换字符串的值,然后打印出来
(“w pwr zwp par”)
我刚刚辛苦了一会儿,并会感激一些帮助:D
答案 0 :(得分:1)
便利地位于当地的互联网上。
intab = 'aeiou'
outtab = '12345'
s = 'this is string example....wow!!!'
print(s.translate({ord(x): y for (x, y) in zip(intab, outtab)}))
答案 1 :(得分:0)
如果您想明确执行循环,可以尝试类似:
intab = 'aeiou'
outtab = '12345'
mapper = {key: value for (key, value) in zip(intab, outtab)}
s = 'this is string example....wow!!!'
output = ''.join(mapper.get(char, char) for char in s)
print(output)