Home

Ricardo Aráoz wrote:
>>On Jul 30, 4:39 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>>
>>>"attn.steven....@gmail.com" <attn.steven....@gmail.com> writes:
>>>
>>>>Recursion is common in functional programming:
>>>>def f(n, l=None):
>>>> if l == None:
>>>> l = []
>>>> if n > 0:
>>>> return f(n/26, l + [n%26])
>>>> else:
>>>> return l
>>>>print f(1000)
>>>
>>>Right, this is functional style, but quite painful in Python (no tail
>>>recursion, and look at all that list copying).
>>
>
> It might actually be :
>
> def f(n):
> if n > 0:
> return ([n%26] + f(n/26))
> else:
> return []
>
> Wouldn't that be ok?
>

You are still copying lists. This wouldn't:

def f(n):
if n>0:
yield n%26
for i in f(n/26):
yield i


James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

previous
next

Re: pyodbc on linux
Re: Database intensive application
Re: Bug in time, part 2
Re: simple question.
Re: i need help:""<
noclegi w mielnie
portal-ekologia.com.pl
typy bukmacherskie
ecommerce
piła spalinowa