[Tutor] Question about login=''.join(choice(lc) for j in range(llen))

Khalid Al-Ghamdi emailkgnow at gmail.com
Tue Apr 3 16:54:12 CEST 2012


Hi,

The following code tries to generate some dummy data for regex exercises.
My question is in reference the line before last:

    dom="".join(choice(lc) for j in range (dlen))

how does the interpreter know what "j" is supposed to refer to when it was
not mentioned prior?


from random import randrange, choice
from string import ascii_lowercase as lc
from sys import maxsize
from time import ctime

tlds = ('com', 'edu', 'net', 'org', 'gov')

for i in range(randrange(5,11)):
    dtint=randrange(maxsize)    #pick a random number to use to generate
random date in next line
    dtstr=ctime(dtint)          #date string
    llen=randrange(4,8)         #login is shorter
    login=''.join(choice(lc) for j in range(llen))
    dlen=randrange(llen,13)     #domain is longer
    dom="".join(choice(lc) for j in range (dlen))

print('{}::{}@{}.{}::{}-{}-{}'.format(dtstr,login,dom,choice(tlds),dtint,llen,dlen))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120403/d57a8c0b/attachment-0001.html>


More information about the Tutor mailing list