Nice post. Two suggestions:
Use string constants to define possible characters:
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))
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.