[newbie] making rows of table with discrete values for different number systems
Jean Dupont
jeandupont314 at gmail.com
Mon Feb 3 10:06:13 EST 2014
Op zondag 2 februari 2014 19:07:38 UTC+1 schreef Roy Smith:
> In article <515e582f-ed17-4d4e-9872-f07f1fda6ed2 at googlegroups.com>,
> Jean Dupont <jeandupont314 at gmail.com> wrote:
>
> > I'm looking for an efficient method to produce rows of tables like this:
> >
> > for base 2
> > 0 0 0 0
> > 0 0 0 1
> > 0 0 1 0
> > 0 0 1 1
> > 0 1 0 0
> > .
> > .
> > .
> > 1 1 1 1
> >
> > for base 3
> > 0 0 0 0 0 0
> > 0 0 0 0 0 1
> > 0 0 0 0 0 2
> > 0 0 0 0 1 0
> > 0 0 0 0 1 1
> > 0 0 0 0 1 2
> > .
> > .
> > 2 2 2 2 2 2
>
> This sounds like a homework problem :-)
>
> > As you can see the rows are always twice the size of the base
>
> Why?
>
> > I _don't_ need to have all rows available together in one array which would
> > become too large for higher value number bases. It's sufficient to produce
> > one row after the other, as I will do further data manipulation on such a row
> > immediately.
>
> What I get out of that is that you don't want to just print them, you
> want to have some function which returns all the generated rows in
> order. The way to do that is with the yield statement. Take a look at
> https://wiki.python.org/moin/Generators for some discussion on how that
> works. Actually, http://stackoverflow.com/questions/231767/
> looks like an even better discussion.
>
> Does that help you any?
Thanks, I'll try to figure out what yield does
kind regards,
jean
More information about the Python-list
mailing list