Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65278
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: [newbie] making rows of table with discrete values for different number systems |
| Date | 2014-02-02 19:10 +0100 |
| Organization | None |
| References | <515e582f-ed17-4d4e-9872-f07f1fda6ed2@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6309.1391364617.18130.python-list@python.org> (permalink) |
Jean Dupont 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 > > As you can see the rows are always twice the size of the base > 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. > > If someone here could suggest best practices to perform this kind of > operations,I'd really appreciate it very much Have a look at itertools.product(): >>> import itertools >>> for row in itertools.product(range(2), repeat=4): ... print(*row) ... 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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