Mr-Programer
Mr-Programer

Reputation: 561

Repeat in range with itertools.product

I need to repeat in range with itertools.product with this code:

            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)

but when I use this code repeat=range(minLength,maxLength) it shows me this error:

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

What's the problem? How can I solve this problem?

Upvotes: 2

Views: 503

Answers (1)

U13-Forward
U13-Forward

Reputation: 71580

You can't do that, use:

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

Upvotes: 3

Related Questions