Well, what you want is just a product of the alphabet, with increasing numbers of elements. You can use [`itertools.product`][1] for this:

    from itertools import product, count
    from string import ascii_lowercase
    
    def generate_labels():
        for n in count(1):
            yield from map("".join, product(*[ascii_lowercase]*n))

Here is what it outputs:

    from itertools import islice
    
    print(list(islice(generate_labels(), 1000)))
    # ['a', 'b', ..., 'z', 'aa', 'ab', ..., 'az', 'ba', 'bb', ..., 'bz', ..., 'za', ..., 'zz', 'aaa', 'aab', ...]

This has the slight disadvantage that the list being passed to `product` gets larger every iteration. But already with \$n=5\$ you can generate \$\sum_{k=1}^n 26^k = 12,356,630\$ labels, and the list is only about `sys.getsizeof([ascii_lowercase]*5) + sys.getsizeof(ascii_lowercase) * 5` = 479 bytes large, so in practice this should not be a problem.


  [1]: https://docs.python.org/3.8/library/itertools.html#itertools.product
  [2]: https://docs.python.org/3.8/library/itertools.html#itertools.combinations_with_replacement
Morty Proxy This is a proxified and sanitized view of the page, visit original site.