counting using variable length string as base

castironpi at castironpi at
Thu Mar 27 12:28:51 CET 2008

On Mar 27, 4:01 am, Peter Otten <__pete... at> wrote:
> 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

For the base, we Arabics use the cardinal; what letters you count in
doesn't change anything.  Don't just spell out numbers, unless: Are
you reading marked-tally.  Or do you want to yield a word and see the
number that it spells out to?  Be there or be around.  I'm bad at
spelling, but I can rearrange linear.

More information about the Python-list mailing list