Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed6.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:howto': 0.09; 'suggestions:': 0.09; 'nesting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'xrange': 0.16; 'wrote:': 0.17; 'drawing': 0.17; 'fairly': 0.21; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'candidate': 0.26; '(e.g.,': 0.27; 'header:X -Complaints-To:1': 0.28; 'this.': 0.29; "i'm": 0.29; 'maybe': 0.29; 'basic': 0.30; 'code': 0.31; 'like:': 0.33; 'to:addr:python- list': 0.33; 'thanks': 0.34; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'level': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'range': 0.60; 'great': 0.64; 'sounds': 0.71; 'received:139': 0.84; 'subject:handle': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Neal Becker Subject: Re: howto handle nested for Date: Fri, 28 Sep 2012 11:52:36 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: 139.85.237.139 User-Agent: KNode/4.9.1 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348847573 news.xs4all.nl 6921 [2001:888:2000:d::a6]:56162 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30409 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? Thanks for the suggestions: I found itertools.product is just great for this.