Here's a piece of code that uses [Python 3.Docs]: itertools.product(*iterables, repeat=1).
Note that the number of generated strings is 62 ** length
, so for testing purposes use small values for length:
import string
import itertools
def generate_strings(length=3):
chars = string.ascii_letters + string.digits # "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for item in itertools.product(chars, repeat=length):
yield "".join(item)