I need to generate all possible permutations (with repetitions) of the characters in a string. If the string is 'abc', the output should be:
aaa aab aac abc ... cbc cca ccb ccc
I can't use the itertools module and I don't want to use recursion (because this is just an example. What I really need will output millions of permutations and I'm afraid to run out of memory)
I can do it like this:
s = 'abc'
for c1 in range(0, 3):
for c2 in range(0, 3):
for c3 in range(0, 3):
print(s[c1]+s[c2]+s[c3])
Basically, I have as many for cycles as the string has characters. Now imagine if the string has length 10, for example!
Is there a better way of doing this?