Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: howto handle nested for (http://www.velocityreviews.com/forums/t952800-re-howto-handle-nested-for.html)

Neal Becker 09-28-2012 03:52 PM

Re: howto handle nested for
 
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.



All times are GMT. The time now is 11:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57