def gen_letters(s,l):
def __gen(s,l):
if l > 1:
for c in 'abcdefghijklmnopqrstuvwxyz ':
__gen(s+c,l-1)
else:
print(1)
for c in 'abcdefghijklmnopqrstuvwxyz ':
yield s+c
return __gen(s,l)
I am trying to generate all combinations of letters in the alphabet of length "l". The intended use for this functions is:
combos = gen_letters('', 10)
The second argument being the length of the combinations to return. For instance, if I wanted to generate all possible 3 char length strings from the alphabet and a space, I should get 19683 combinations. When trying to use "next(combos)" or "for combo in combos:" (even on the first next()) I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
Help is much appreciated :)