0
is there a way to convert that for loop into normal for loop?
2 odpowiedzi
+ 6
We should keep in mind, that string concatenation ( here with "password += random.choice(string.ascii_letters + string.digits)") creates a new string object each time we add a new character to the password. This is not an issue with an iteration for a passeword, but can increase execution time when iteration grows.
Instead of a string varibale, a list can be used, and the characters coming from random.choice() can be appended to it.
An other possible improvement can be using random.choices(), so we can append the complete number of characters at one run.
+ 4
1.) Create an empty string 'password'.
2.) Start a for loop.
3.) Within the body, add the expression from the list comprehension to the empty string.