Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30410 > unrolled thread

Re: howto handle nested for

Started byPeter Otten <__peter__@web.de>
First post2012-09-28 17:53 +0200
Last post2012-09-28 17:53 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: howto handle nested for Peter Otten <__peter__@web.de> - 2012-09-28 17:53 +0200

#30410 — Re: howto handle nested for

FromPeter Otten <__peter__@web.de>
Date2012-09-28 17:53 +0200
SubjectRe: howto handle nested for
Message-ID<mailman.1568.1348847645.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web