loading...

re: Password generator using python VIEW POST

FULL DISCUSSION
 

Nice post. Two suggestions:

Use string constants to define possible characters:

import string
chars = string.letter + string.digits + string.punctuation

Often “simple for loops” can be prevented in Python. In this case, you can do:

return “”.join(random.choices(chars, k=num))

Or if you insist on using choice:
return “”.join(random.choice(chars) for _ in range(num))

code of conduct - report abuse