beginnerdev
beginnerdev

Reputation: 35

Itertool.product at to string

Hi I starting learning python.

I have to do a small work to generate password using itertool. the only thing I don't understand how to convert this result :

itertools.product object at 0x03493BE8

to something readeable.

How can I convert it to get a string or something similar ? Here is my code :

  for CharLength in range(12):
        words= (itertools.product(Alphabet, repeat=CharLength))
        print(words)

Upvotes: 1

Views: 1576

Answers (2)

abc
abc

Reputation: 11929

itertools.product() returns a generator. To print them you can use the * operator.

for char_len in range(12):
    words = itertools.product(alphabet, repeat=char_len)
    print(*words)

Upvotes: 2

Mureinik
Mureinik

Reputation: 311563

itertools.product returns a generator object. If you wish, you could go over it and convert it to a list so it's easier to view its contents, e.g. by using a list comprehension:

words = [w for w in itertools.product(Alphabet, repeat=CharLength)]

Upvotes: 0

Related Questions