Re: howto handle nested for

Discussion in 'Python' started by Tim Chase, Sep 28, 2012.

  1. Tim Chase

    Tim Chase Guest

    On 09/28/12 09:39, 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?


    There was a good discussion on this back in 2008 that might be worth
    reading over. For some reason the mail.python.org archives[1] seem
    to have broken threading on this topic (Andrew Reedick's reply using
    exec() is waaay down in the archive, disassociated from the thread),
    so here it is archived somewhere else where the 2 pages of threading
    seems more manageable/accurate:

    http://www.velocityreviews.com/forums/t585147-creating-unique-combinations-from-lists.html

    -tkc

    [1]
    http://mail.python.org/pipermail/python-list/2008-January/487851.html
     
    Tim Chase, Sep 28, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neal Becker

    howto handle nested for

    Neal Becker, Sep 28, 2012, in forum: Python
    Replies:
    1
    Views:
    154
    Wojtek
    Sep 28, 2012
  2. Laszlo Nagy

    Re: howto handle nested for

    Laszlo Nagy, Sep 28, 2012, in forum: Python
    Replies:
    1
    Views:
    164
    Neil Cerutti
    Sep 28, 2012
  3. Ian Kelly

    Re: howto handle nested for

    Ian Kelly, Sep 28, 2012, in forum: Python
    Replies:
    2
    Views:
    170
    Hans Mulder
    Sep 29, 2012
  4. Neal Becker

    Re: howto handle nested for

    Neal Becker, Sep 28, 2012, in forum: Python
    Replies:
    0
    Views:
    149
    Neal Becker
    Sep 28, 2012
  5. Peter Otten

    Re: howto handle nested for

    Peter Otten, Sep 28, 2012, in forum: Python
    Replies:
    0
    Views:
    137
    Peter Otten
    Sep 28, 2012
Loading...

Share This Page