python递增字符循环

时间:2013-03-01 01:29:03

标签: python python-3.x

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

希望实现一个执行以下操作的循环: 循环通过charset1 a-Z。如果没有匹配,则添加循环,以便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 

1 个答案:

答案 0 :(得分: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))