Fast recursive generators?

Discussion in 'Python' started by Michael McGlothlin, Oct 28, 2011.

  1. I'm trying to generate a list of values where each value is dependent
    on the previous value in the list and this bit of code needs to be
    repeatedly so I'd like it to be fast. It doesn't seem that
    comprehensions will work as each pass needs to take the result of the
    previous pass as it's argument. map() doesn't seem likely. filter() or
    reduce() seem workable but not very clean. Is there a good way to do
    this? About the best I can get is this:

    l = [ func ( start ) ]
    f = lambda a: func ( l[-1] ) or a
    filter ( f, range ( big_number, -1, -1 ) )


    I guess I'm looking for something more like:

    l = do ( lambda a: func ( a ), big_number, start )


    Thanks,
    Michael McGlothlin
     
    Michael McGlothlin, Oct 28, 2011
    #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. Replies:
    0
    Views:
    701
  2. Carlos Ribeiro

    Style question on recursive generators

    Carlos Ribeiro, Oct 18, 2004, in forum: Python
    Replies:
    22
    Views:
    645
    Terry Reedy
    Oct 20, 2004
  3. Talin
    Replies:
    6
    Views:
    771
    Tim Peters
    Oct 31, 2005
  4. n00m
    Replies:
    12
    Views:
    1,139
  5. vamsi
    Replies:
    21
    Views:
    2,145
    Keith Thompson
    Mar 9, 2009
Loading...

Share This Page