Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4193
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Fibonacci series recursion error |
| Date | Sat, 30 Apr 2011 10:14:46 +0200 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <ipggdo$741$1@r03.glglgl.eu> (permalink) |
| References | <a78a0ffd-03cc-4540-addb-b8e206d165d5@n2g2000prj.googlegroups.com> <KtMup.29280$8U5.7734@newsfe20.iad> <1zMup.12761$rB2.10164@newsfe21.iad> <b9Nup.59945$yp3.50640@newsfe09.iad> <mailman.1012.1304144107.9059.python-list@python.org> <%4Pup.21891$vC5.6549@newsfe01.iad> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| User-Agent | Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 |
| In-Reply-To | <%4Pup.21891$vC5.6549@newsfe01.iad> |
| Lines | 44 |
| NNTP-Posting-Date | 30 Apr 2011 10:20:04 CEST |
| NNTP-Posting-Host | 40b98ed0.newsspool2.arcor-online.net |
| X-Trace | DXC=`PQe<kXXK8;^cW`WBF>WQ<A9EHlD;3Yc24Fo<]lROoR18kF<OcfhCO;PR=AWKhdYJ7K8FCa6^2FW2OLF_]FfFg8?\8d@`\i_MP: |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4193 |
Show key headers only | View raw
Am 30.04.2011 09:43 schrieb harrismh777:
> On the other hand, I am very much interested in "yield," because of its
> obvious persistent state, On the other hand, I don't like you fib()
> function because it does not encapsulate the fib generator. I suppose
> you are considering whatever module is holding the fib() code as the
> encapsulation, but I thought the idea from the OP was to create a
> generator that could be called and return a list... this is a little goofy:
> list(islice(fib(), X))
>
> when what was wanted is:
>
> list = fib(X)
You can have both with the following:
def fib(max=None):
a = b = 1
while max is None or a <= max:
yield a
a, b = b, a+b
from itertools import islice
flist = list(islice(fib(), 100000))
flist2 = list(fib(100000))
or - if even the latter is unwanted -
def fibgen(max=None):
a = b = 1
while max is None or a <= max:
yield a
a, b = b, a+b
def fib(max=None, num=None):
if num is None:
return list(fibgen(max=max))
else:
from itertools import islice
return list(islice(fib(max=max), num))
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Fibonacci series recursion error harrismh777 <harrismh777@charter.net> - 2011-04-30 02:43 -0500
Re: Fibonacci series recursion error Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-30 10:14 +0200
Re: Fibonacci series recursion error harrismh777 <harrismh777@charter.net> - 2011-04-30 15:41 -0500
Re: Fibonacci series recursion error Peter Otten <__peter__@web.de> - 2011-04-30 18:07 +0200
Re: Fibonacci series recursion error harrismh777 <harrismh777@charter.net> - 2011-04-30 15:51 -0500
csiph-web