python - 如何将输入转换为每个字母包含一个字符的列表?
问题描述
我想制作一个可以破解密码的密码破解器。我不明白如何将代码的 (n) 字母放入字符串并将其转回列表并将其打印到终端中。
#This is python code
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 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".split() #needs double alphabet as code will add up: w --> h, or the list will be out of range
while True:
saves = []
crack = ""
totalSaves = []
code = input("Enter code >")
codeIndex = 0
for i in range(26): #Length of alphabet
for i in range(len(code)): #length of code
#get the first letter of code into the saves code in here
#use saves[codeIndex] if possible
#I want the code breaker to be sort of like this: a --> c. At this case, I want codeIndex to be 2. If possible, I want to put the letters into saves[].
crack = "".join(saves) #unsure about this use
totalSaves.append(crack)
saves = []
crack = ""
printIndex = 0
for i in range(26):
print(totalSaves[printIndex])
totalSaves += 1
如果你不明白,我很抱歉。
解决方案
如果你想打破和组合列表中的字母,你可以这样做。
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 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"
alphabet_list = alphabet.split()
split_n = 5
result = []
for i in range(0, len(alphabet_list), split_n):
result.append("".join(alphabet_list[i:i+split_n]))
print(result)
你会得到输出:['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy', 'zabcd', 'efghi', 'jklmn', 'opqrs', 'tuvwx', 'yz']
推荐阅读
- prolog - 将元素增量添加到变量
- c# - 在使用条件测试后仍会评估空值
- python-3.x - 根据烧瓶中的其他选择选项显示选择字段
- amazon-web-services - 使用dynamoDB流触发理解同步调用的Lambda函数
- python - Python - “追加(列表)”和“追加(列表[:])”有什么不同?
- azure-ad-b2c - 自定义策略中的 Azure B2C MFA 电话因素验证重试处理
- c# - 没有 BeginLifeTimeScope 的 Autofac InstancePerLifeTimeScope
- python - 在 Python 中打印大型 JSON 文件的前几行
- java - 设定火花内的组合
- java - 无法增加 java 堆大小