counting using variable length string as base

Peter Otten __peter__ at
Thu Mar 27 10:01:39 CET 2008

Grimsqueaker wrote:

> That seems to give me the items in the list back in an iterator. Am I
> using it incorrectly?

With Dan's functions in you can do the following:

>>> from cartesian import * 
>>> def count(digits):
...     args = []
...     while 1:
...             args.append(digits)
...             for n in string_cartesian_product(*args):
...                     yield n
>>> from itertools import islice
>>> print " ".join(islice(count("abc"), 30))
a b c aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc baa bab
bac bba bbb bbc bca bcb bcc


More information about the Python-list mailing list