gpt4 book ai didi

python - 从单个列表创建多个列表

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:25 25 4
gpt4 key购买 nike

所以我试图在 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 < 的矩阵em>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)

关于python - 从单个列表创建多个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43324107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com