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


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

Re: Fast recursive generators?

Started by"Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
First post2011-10-29 00:18 -0300
Last post2011-10-29 02:10 -0700
Articles 3 — 2 participants

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: Fast recursive generators? "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-10-29 00:18 -0300
    Re: Fast recursive generators? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-29 02:10 -0700
    Re: Fast recursive generators? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-29 02:10 -0700

#15128 — Re: Fast recursive generators?

From"Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
Date2011-10-29 00:18 -0300
SubjectRe: Fast recursive generators?
Message-ID<mailman.2300.1319858257.27778.python-list@python.org>
En Fri, 28 Oct 2011 15:10:14 -0300, Michael McGlothlin  
<michaelm@plumbersstock.com> escribió:

> 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 )

What about a generator function?

def my_generator():
   prev = 1
   yield prev
   while True:
     this = 2*prev
     yield this
     prev = this

print list(itertools.islice(my_generator(), 10))

-- 
Gabriel Genellina

[toc] | [next] | [standalone]


#15129

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-10-29 02:10 -0700
Message-ID<mailman.2301.1319879431.27778.python-list@python.org>
In reply to#15128
I am thinking the bye code compiler in python can be faster  if all known immutable instances up to the execution    are compiled immutable objects to be assigned.     

[toc] | [prev] | [next] | [standalone]


#15131

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-10-29 02:10 -0700
Message-ID<31591999.1755.1319879427800.JavaMail.geo-discussion-forums@prlk36>
In reply to#15128
I am thinking the bye code compiler in python can be faster  if all known immutable instances up to the execution    are compiled immutable objects to be assigned.     

[toc] | [prev] | [standalone]


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


csiph-web