0

好的,我正在尝试创建一个增量列表循环。

希望实现一个执行以下操作的循环:循环通过 charset1 aZ。如果没有找到匹配项,则添加到循环中,所以 aa-ZZ 等等。似乎找不到做循环的好方法。

import itertools
result = "password"
charset1 = ['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']
charset2 = ['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']
charcount = 1

while i != result
    finalchar = charset1[-1]
    finalset = charset1[-1] * charcount
    for check in 
4

1 回答 1

1

您可以使用以下itertools.productrepeat参数一起使用的模板:

from string import ascii_letters
from itertools import product

for i in range(1, 3): # do 1 and 2 chars
    chars = product(ascii_letters, repeat=i)
    for combo in chars:
        print(''.join(combo))
于 2013-03-01T06:22:15.473 回答