string
module does not literary have len
you might want to try this:
Python2:
rand_str = lambda n: ''.join([random.choice(string.lowercase) for i in range(n)])
# Now to generate a random string of length 10
s = rand_str(10)
Python3:
rand_str = lambda n: ''.join([random.choice(string.ascii_lowercase) for i in range(n)])
# Now to generate a random string of length 10
s = rand_str(10)
random.choice
returns a single character and 10 such characters are joined using the join
function.
EDIT
lambda n : ...
creates a lambda function which takes n
as the argument.
''.join(sequence)
joins a sequence into a string with empty string (''
) between them i.e. it simply joins characters into words.
'.'.join(['a','b','c'])
will for example, return a.b.c
.