Sep-27-2020, 08:48 PM
Keep track of the incremental part separately and then tack it on to the end. Do you want to always have exactly the same number of characters in the unique part, or do you want to add new characters if you run out?
import string from itertools import product def unique_sequence_generator(): letterspace = (string.ascii_lowercase + string.ascii_uppercase + string.digits + "-_") for seq in product(letterspace, repeat=3): yield "".join(seq) i = unique_sequence_generator() for _ in range(5): print(next(i))This creates an iterator that will return all the 3-character sequences of the letterspace. Just call
next()
on it or put it in a for loop to pull elements from it.Output:aaa
aab
aac
aad
aae