正在做 pythonchallenge,Q2,我自己用的是字典的方法
words ="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. "
secret = {"a":"c","b":"d","c":"e","d":"f","e":"g","f":"h ","g":"i","h ":"j","i":"k","j":"l","k":"m","l":"n","m":"o","n":"p","o":"q","p":"r","q":"s","r":"t","s":"u","t":"v","u":"w","v":"x","w":"y","x":"z","y":"a","z":"b"}
answer=[]
i=0
while i < len(words):
j = words[i]
if j in secret.keys():
answer.append(secret[j])
else:
answer.append(j)
i = i +1
print(answer)
print("".join(answer))
测试发现 最后的 answer 这个 list 是没有问题的, 内容是
['i', ' ', 'h ', 'o', 'p', 'e', ' ', 'y', 'o', 'u', ' ', 'd', 'i', 'd', 'n', 't', ' ', 't', 'r', 'a', 'n', 's', 'l', 'a', 't', 'e', ' ', 'i', 't', ' ', 'b', 'y', ' ', 'h ', 'a', 'n', 'd', '.', ' ', 't', 'h ', 'a', 't', 's', ' ', 'w', 'h ', 'a', 't', ' ', 'c', 'o', 'm', 'p', 'u', 't', 'e', 'r', 's', ' ', 'a', 'r', 'e', ' ', 'f', 'o', 'r', '.', ' ', 'd', 'o', 'i', 'n', 'g', ' ', 'i', 't', ' ', 'i', 'n', ' ', 'b', 'y', ' ', 'h ', 'a', 'n', 'd', ' ', 'i', 's', ' ', 'i', 'n', 'e', 'f', 'f', 'i', 'c', 'i', 'e', 'n', 't', ' ', 'a', 'n', 'd', ' ', 't', 'h ', 'a', 't', "'", 's', ' ', 'w', 'h ', 'y', ' ', 't', 'h ', 'i', 's', ' ', 't', 'e', 'x', 't', ' ', 'i', 's', ' ', 's', 'o', ' ', 'l', 'o', 'n', 'g', '.', ' ', 'u', 's', 'i', 'n', 'g', ' ', 's', 't', 'r', 'i', 'n', 'g', '.', 'm', 'a', 'k', 'e', 't', 'r', 'a', 'n', 's', '(', ')', ' ', 'i', 's', ' ', 'r', 'e', 'c', 'o', 'm', 'm', 'e', 'n', 'd', 'e', 'd', '.', ' ', 'n', 'o', 'w', ' ', 'a', 'p', 'p', 'l', 'y', ' ', 'o', 'n', ' ', 't', 'h ', 'e', ' ', 'u', 'r', 'l', '.', ' ']
但是最后使用 join 将 list 转变成 str 时,结果就变成了
i h ope you didnt translate it by h and. th ats wh at computers are for. doing it in by h and is inefficient and th at's wh y th is text is so long. using string.maketrans() is recommended. now apply on th e url.
注意其中莫名奇妙的多了几个空格,正常应该是
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
请教下大家这莫名奇妙的空格是怎么被输出的?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.