Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: howto handle nested for

Reply
Thread Tools

Re: howto handle nested for

 
 
Neal Becker
Guest
Posts: n/a
 
      09-28-2012
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: howto handle nested for Ian Kelly Python 2 09-29-2012 12:41 PM
Re: howto handle nested for Laszlo Nagy Python 1 09-28-2012 08:38 PM
Re: howto handle nested for Peter Otten Python 0 09-28-2012 03:53 PM
Re: howto handle nested for Tim Chase Python 0 09-28-2012 03:28 PM
howto handle nested for Neal Becker Python 1 09-28-2012 02:51 PM



Advertisments