counting using variable length string as base

Peter Otten __peter__ at web.de
Thu Mar 27 05:01:39 EDT 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 cartesian.py 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

Peter



More information about the Python-list mailing list