Below is a python script that generates the sequence
['a', 'b' .. 'z', 'aa', 'ab' .. 'az', 'ba', 'bb' .. 'zz', 'aaa', 'aab', ..]
This is essentially counting in base 27, replacing every digit with the n-th letter of the alphabet, but skipping any number that would have a
import string def gen_labels(): i = 0 n = len(string.ascii_lowercase) + 1 while True: i += 1 j = i result = '' while True: c = j % n if not c: break result = string.ascii_lowercase[c-1] + result if j < n: break j = j // n if c: yield result print(list(zip(gen_labels(), range(1000))))
However, the code seems overly long to me for generating such a straightforward series and it's doing a lot of work to break down values that would have a
'0' in them in base 27.
What is a more efficient way of generating the exact same (infinite) series?
Note that I'm not worried that much about speed, but mainly about the brevity / simplicity of the algorithm - it seems overly complicated, but I don't really see my way to an efficient realisation.