gpt4 book ai didi

python - 使用 itertools.product 在范围内重复

转载 作者:行者123 更新时间:2023-12-01 01:14:22 25 4
gpt4 key购买 nike

我需要使用以下代码在 itertools.product 范围内重复:

            minLength=InputInt(" Please Enter the Min Length of Your Word : ")
maxLength=InputInt(" Please Enter the Max Length of Your Word : ")
characters=input(" Please Enter the Character of Your Word : ")

res = itertools.product(characters, repeat=range(minLength,maxLength))
for i in res:
print(' Password Created : ',''.join(i), end='\r',flush=True)

但是当我使用此代码repeat=range(minLength,maxLength)时,它向我显示此错误:

res = itertools.product(characters, repeat=range(minLength,maxLength)) TypeError: 'range' object cannot be interpreted as an integer

有什么问题吗?我该如何解决这个问题?

最佳答案

你不能这样做,请使用:

res = [x for i in range(minLength,maxLength) for x in itertools.product(characters, repeat=i)]

关于python - 使用 itertools.product 在范围内重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54500882/

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