【发布时间】:2016-05-12 20:16:12
【问题描述】:
我有下面的程序,它被传递给另一个函数,该函数简单地打印出原始和加密的消息。我想知道如何简化这个程序,特别是“match = zip”和“change = (reduce(lambda”) 行。如果可以在不使用 lambda 的情况下做到这一点,我该怎么做?
from itertools import cycle
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
def vigenereencrypt(message,keyword):
output = ""
match = zip(message.lower(),cycle(keyword.lower()))
for i in match:
change = (reduce(lambda x, y: alphabet.index(x) + alphabet.index(y), i)) % 26
output = output + alphabet[change]
return output.lower()
【问题讨论】:
标签: python python-2.7 lambda vigenere