Shashank
Shashank

Reputation: 353

Simple code to generate a wordlist of specific type

I need to generate a word list which as first 3 of alphabets 4th a number and 5th again an alphabet . This is the patter . I need to get all possible list of that pattern.

Example aaa0a aaa0b .... to zzz9z

My try was

import string
from random import *
password =''.join(choice(string.lowercase) for x in range(3))
password +=choice(string.digits)
password +=choice(string.lowercase)
print password

I know its the worst code. Still I made a try myself.

And I wanted to print the output in a text file, how to do that?

Upvotes: 0

Views: 129

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180540

from string import ascii_lowercase, digits
from itertools import product, combinations_with_replacement as cr, chain

for p in product(cr(ascii_lowercase,3), digits,ascii_lowercase):
    print("".join(chain.from_iterable(p)))

To write it to a file:

with open("foo.txt", "w") as f:
    f.writelines("".join(chain.from_iterable(p)) + "\n"
                 for p in product(cr(ascii_lowercase, 3), digits, ascii_lowercase))

Which should give you 851761 unique lines ;)

Upvotes: 2

Related Questions