Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30410
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!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 | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*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; 'nesting': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 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; "i'm": 0.29; 'maybe': 0.29; 'basic': 0.30; 'code': 0.31; 'print': 0.32; 'like:': 0.33; 'to:addr:python-list': 0.33; '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; 'sounds': 0.71; 'subject:handle': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: howto handle nested for |
| Date | Fri, 28 Sep 2012 17:53:54 +0200 |
| Organization | None |
| References | <k44cr4$jtj$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p50849cab.dip.t-dialin.net |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1568.1348847645.27098.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348847645 news.xs4all.nl 6934 [2001:888:2000:d::a6]:57729 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:30410 |
Show key headers only | View raw
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?
for s in itertools.product(range(n_syms), repeat=6):
print s
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: howto handle nested for Peter Otten <__peter__@web.de> - 2012-09-28 17:53 +0200
csiph-web