所以我试图在 python 中创建一个山密码,但我不确定如何将输入分解成多个列表,每个列表现在都有 2 个字符。
我现在拥有的是
mess = input('What is the message: ').upper()
m = [mess[i: i + 2] for i in range(0, len(mess), 2)]
它将输出每对字符,但只会将其放入一个列表中
['CI', 'PH', 'ER']
我想将它们分解以开始乘以加密矩阵,但还不能这样做,我不确定如何将其变成一个矩阵 numpy 可以作为 2 x n 处理。
这应该现在工作:
新编辑:
words = input()
the_words = words.split()
new_list = []
for i in the_words:
for b in range(0, len(i), 2):
if b+1 < len(i)-1:
new_list.append([i[b], i[b+1]])
print(new_list)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句