将itertools 2产品与指定数量的变量组合

tjvv9vkg  于 2022-10-30  发布在  Python
关注(0)|答案(1)|浏览(265)

我正在尝试制作一个产品,它有2个列表,每个列表有3个变量,每个变量组合成1个列表/产品
我尝试合并3个字母和3个数字,所以我用字符串来表示,这是伪代码。

product(string.ascii_lowercase, repeat=int(3)) + product(string.digits, repeat=int(3))

i have gotten thi working but this goes through all letters before combining with numbers so its rather slow

product(string.ascii_lowercase+ string.digits, repeat=int(6))

`

gijlo24d

gijlo24d1#

basically create two iterators like you are

alphas = product(string.ascii_lowercase, repeat=int(3))
numerics = product(string.digits, repeat=int(3))

turn it into lists instead of iterators

alphas = list(alphas)
numerics = list(numerics)

then just get the product of those two

potential_solutions = product(alphas,numerics)
for combo in potential_solutions:
    print(combo[0] + combo[1])

and you should get something that looks like your passwords .... its still alot of combinations ... but its pretty fast

相关问题