Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'sufficient': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'subject:number': 0.09; 'suggest': 0.14; 'itertools': 0.16; 'other,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:making': 0.16; 'subject:values': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'tables': 0.26; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'array': 0.29; "i'm": 0.30; 'jean': 0.31; 'could': 0.34; 'subject:with': 0.35; 'really': 0.36; 'method': 0.36; 'too': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject: ': 0.61; 'further': 0.61; 'kind': 0.63; 'such': 0.63; 'become': 0.64; 'here': 0.66 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: [newbie] making rows of table with discrete values for different number systems Date: Sun, 02 Feb 2014 19:10:32 +0100 Organization: None References: <515e582f-ed17-4d4e-9872-f07f1fda6ed2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bc76.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391364617 news.xs4all.nl 2965 [2001:888:2000:d::a6]:49598 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65278 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