我想制作一个playfair密码,但我无法将我的变量放到正确的位置。追加到python中的嵌套列表中
我有一个函数,它一次编码2个纯文本字母并返回编码的等价物,但它只接受单个字母的2个参数(在字符串中)。我需要帮助让我的列表分开,然后编码这对。
这是我
def function(plaintext):
temp_hold = ''
encode_out = ''
sendout = ''
#breaks into pairs of 2 (list within a list)
temp_hold = [plaintext[i:i+2] for i in range(0, len(plaintext), 2)]
for i in range(len(temp_hold)):
for j in range(len(temp_hold)):
encode_out = encode_pair(temp_hold[i][j], temp_hold[i][j])
print encode_out
# encode pair takes (a,b) and returns its encoded value
print function("abcd") # should print HSCI
[在python中附加到嵌套列表](http://stackoverflow.com/questions/13763157/appending-to-a-nested-list-in -python) – lurker 2014-10-31 13:03:05