[Tutor] fibonacci

Bob Gailer ramrom@earthling.net
Fri Feb 14 11:37:23 2003


--=======185173EC=======
Content-Type: text/plain; x-avg-checked=avg-ok-4FDF15CC; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 01:24 PM 2/14/2003 +0100, Gregor Lingl wrote:
>def fib1liner(n, f=[0,1]):
>    return(n+1>len(f))and[(lambda x:f.append(f[-2]+f[-1]))(i)for i in 
> range(n+1-len(f))]and 0 or f[n]

Thanks for a really great example of what can be done using and, or, 
comprehension. FWIW this can be simplified to:

def fib1liner(n, f=[0,1]):
    return n>1 and[(lambda:f.append(f[-2]+f[-1]))()for i in range(n-1)]and 
0 or f[n]


Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======185173EC=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-4FDF15CC
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.454 / Virus Database: 253 - Release Date: 2/10/2003

--=======185173EC=======--