I Made Simple Generator,, Is there any faster way ??

Posted by Rami Jarrar on Stack Overflow See other posts from Stack Overflow or by Rami Jarrar
Published on 2010-03-12T13:58:54Z Indexed on 2010/03/12 14:07 UTC
Read the original article Hit count: 232

Filed under:

Hi, i do like this:

import time

f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
    for l in range(33,127):
        if n==1:
            b = chr(l) + '\n'
            f.write(b)
            hh += 1 
        elif n==2:           
            for s0 in range(33, 127):
                b = chr(l) + chr(s0) + '\n'
                f.write(b)
                hh += 1
        elif n==3:          
            for s0 in range(33, 127):
                for s1 in range(33, 127):
                    b = chr(l) + chr(s0) + chr(s1) + '\n'
                    f.write(b)
                    hh += 1 
        elif n==4:    
            for s0 in range(33, 127):
                for s1 in range(33, 127):
                    for s2 in range(33,127):
            b = chr(l) + chr(s0) + chr(s1) + chr(s2) + '\n'
            f.write(b)
            hh += 1 
######################################
print "We Made %d Words." %(hh)
######################################
f.close()

So, is there any faster method to make it faster,,

© Stack Overflow or respective owner

Related posts about python