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


Groups > comp.lang.python > #15128

Re: Fast recursive generators?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'oct': 0.02; 'func': 0.09; 'likely.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.14; 'this:': 0.15; 'from:addr:yahoo.com.ar': 0.16; 'function?': 0.16; 'lambda': 0.16; 'trying': 0.21; 'this?': 0.21; "doesn't": 0.23; 'code': 0.25; 'guess': 0.25; "i'm": 0.26; 'repeatedly': 0.28; 'bit': 0.28; 'pass': 0.28; 'yield': 0.28; 'print': 0.29; 'seem': 0.30; '-1,': 0.30; 'clean.': 0.30; 'subject:?': 0.31; 'michael': 0.31; 'values': 0.31; 'dependent': 0.32; 'skip:l 30': 0.32; 'list': 0.32; 'to:addr:python-list': 0.32; 'there': 0.33; 'header :User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'filter': 0.34; 'something': 0.36; 'fri,': 0.36; 'but': 0.37; 'received:org': 0.37; "i'd": 0.39; "it's": 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; '2011': 0.62; 'received:190': 0.74; '-0300,': 0.84; 'genellina': 0.84; 'gabriel': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Gabriel Genellina" <gagsl-py2@yahoo.com.ar>
Subject Re: Fast recursive generators?
Date Sat, 29 Oct 2011 00:18:04 -0300
References <CAG+HS+53dEnqLK-7P7TWZJmsmQd6ommzyd4SJ1uO=i11rfiz=A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed; delsp=yes
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 190.2.4.25
User-Agent Opera Mail/11.52 (Win32)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2300.1319858257.27778.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1319858257 news.xs4all.nl 6974 [2001:888:2000:d::a6]:48336
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15128

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web