Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65276

Re: [newbie] making rows of table with discrete values for different number systems

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: [newbie] making rows of table with discrete values for different number systems
Date 2014-02-02 13:07 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-AF6262.13073802022014@news.panix.com> (permalink)
References <515e582f-ed17-4d4e-9872-f07f1fda6ed2@googlegroups.com>

Show all headers | View raw


In article <515e582f-ed17-4d4e-9872-f07f1fda6ed2@googlegroups.com>,
 Jean Dupont <jeandupont314@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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[newbie] making rows of table  with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-02 09:44 -0800
  Re: [newbie] making rows of table  with discrete values for different number systems Roy Smith <roy@panix.com> - 2014-02-02 13:07 -0500
    Re: [newbie] making rows of table  with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 07:06 -0800
  Re: [newbie] making rows of table with discrete values for different number systems Peter Otten <__peter__@web.de> - 2014-02-02 19:10 +0100
    Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-02 12:51 -0800
      Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-02 17:56 -0800
        Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 07:05 -0800
          Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-03 07:34 -0800
            Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 11:37 -0800
              Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-03 11:50 -0800
                Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont115@gmail.com> - 2014-02-04 01:18 -0800
              Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-03 11:52 -0800
          Re: [newbie] making rows of table with discrete values for different number systems Terry Reedy <tjreedy@udel.edu> - 2014-02-03 16:50 -0500
            Re: [newbie] making rows of table with discrete values for different number systems Rustom Mody <rustompmody@gmail.com> - 2014-02-03 18:48 -0800
  Re: [newbie] making rows of table  with discrete values for different number systems Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-04 00:11 +0000

csiph-web