python -> combinations of numbers and letters

Posted by tekknolagi on Stack Overflow See other posts from Stack Overflow or by tekknolagi
Published on 2011-01-18T02:05:53Z Indexed on 2011/01/18 2:53 UTC
Read the original article Hit count: 167

Filed under:
|
|
|
|
#!/usr/bin/python
import random
lower_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

all = []
all = " ".join("".join(lower_a) + "".join(upper_a) + "".join(num))
all = all.split()
x = 1
c = 1
while x < 10:
        y = []
        for i in range(c):
                a = random.choice(all)
                y.append(a)
        print "".join(y)
        x += 1
        c += 1

what i have now outputs something like the following:

5
hE
HAy
1kgy
Pt6JM
2pFuCb
Jv5osaX
5q8PwWAO
SvHWRKfI5

how can i make it systematically go through every combination of letters (upper and lowercase) for a given length, then add 1 to that length and repeat the process?

© Stack Overflow or respective owner

Related posts about python

Related posts about arrays