Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'broken': 0.03; 'url:pipermail': 0.05; 'subject:howto': 0.09; 'cc:addr:python- list': 0.10; '-tkc': 0.16; 'archive,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'nesting': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'threading': 0.16; 'xrange': 0.16; 'wrote:': 0.17; 'drawing': 0.17; 'discussion': 0.20; 'fairly': 0.21; 'cc:2**0': 0.23; 'seems': 0.23; 'somewhere': 0.24; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'looks': 0.26; 'candidate': 0.26; '[1]': 0.27; 'topic': 0.27; '(e.g.,': 0.27; "i'm": 0.29; 'maybe': 0.29; 'basic': 0.30; 'code': 0.31; 'url:python': 0.32; 'like:': 0.33; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'level': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'where': 0.40; 'url:mail': 0.40; 'range': 0.60; 'back': 0.62; 'worth': 0.63; 'more': 0.63; 'here': 0.65; 'reply': 0.66; 'sounds': 0.71; 'received:50.22': 0.84; 'subject:handle': 0.84; 'url:forums': 0.84 Date: Fri, 28 Sep 2012 10:28:21 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: Neal Becker Subject: Re: howto handle nested for References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348846037 news.xs4all.nl 6973 [2001:888:2000:d::a6]:43053 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30405 On 09/28/12 09:39, Neal Becker wrote: > I know this should be a fairly basic question, but I'm drawing a blank. > > I have code that looks like: > > for s0 in xrange (n_syms): > for s1 in xrange (n_syms): > for s2 in xrange (n_syms): > for s3 in xrange (n_syms): > for s4 in range (n_syms): > for s5 in range (n_syms): > > Now I need the level of nesting to vary dynamically. (e.g., maybe I need to add > for s6 in range (n_syms)) > > Smells like a candidate for recursion. Also sounds like a use for yield. Any > suggestions? There was a good discussion on this back in 2008 that might be worth reading over. For some reason the mail.python.org archives[1] seem to have broken threading on this topic (Andrew Reedick's reply using exec() is waaay down in the archive, disassociated from the thread), so here it is archived somewhere else where the 2 pages of threading seems more manageable/accurate: http://www.velocityreviews.com/forums/t585147-creating-unique-combinations-from-lists.html -tkc [1] http://mail.python.org/pipermail/python-list/2008-January/487851.html