Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30393 > unrolled thread
| Started by | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| First post | 2012-09-28 10:39 -0400 |
| Last post | 2012-09-28 16:51 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
howto handle nested for Neal Becker <ndbecker2@gmail.com> - 2012-09-28 10:39 -0400
Re: howto handle nested for Alister <alister.ware@ntlworld.com> - 2012-09-28 14:42 +0000
Re: howto handle nested for Wojtek <decyk@nospam.poczta.fm> - 2012-09-28 16:51 +0200
| From | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| Date | 2012-09-28 10:39 -0400 |
| Subject | howto handle nested for |
| Message-ID | <mailman.1555.1348843184.27098.python-list@python.org> |
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?
[toc] | [next] | [standalone]
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Date | 2012-09-28 14:42 +0000 |
| Message-ID | <gHi9s.35010$AT4.24306@fx19.am4> |
| In reply to | #30393 |
On Fri, 28 Sep 2012 10:39:32 -0400, 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? It definitely looks like for is the wrong way to go for this without more information on the reason why it is difficult to say what the correct approach would be -- Calm down, it's *____only* ones and zeroes.
[toc] | [prev] | [next] | [standalone]
| From | Wojtek <decyk@nospam.poczta.fm> |
|---|---|
| Date | 2012-09-28 16:51 +0200 |
| Message-ID | <5065b96c$0$1213$65785112@news.neostrada.pl> |
| In reply to | #30394 |
W dniu 2012-09-28 16:42, Alister pisze: > On Fri, 28 Sep 2012 10:39:32 -0400, 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? > > It definitely looks like for is the wrong way to go for this > without more information on the reason why it is difficult to say what > the correct approach would be > > > it's well described in head first: python book ;) check this sources from this book http://www.headfirstlabs.com/books/hfpython/code/chapter1.zip hope it helps, regards
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web