Home

On Jul 30, 3:48 pm, beginner <zyzhu2...@gmail.com> wrote:
> Hi,
>
> If I have a number n and want to generate a list based on like the
> following:
>
> def f(n):
> l=[]
> while n>0:
> l.append(n%26)
> n /=26
> return l
>
> I am wondering what is the 'functional' way to do the same.
>


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)

--
Hope this helps,
Steven

next

Re: const static initialization in Visual Studio
Re: Runtime optional interface
Re: An ordered dictionary for the Python library?
parameter list notation
Re: Partial Implementation of templates
Nasze Dzieci
Fundacja Avalon
Fundacja Sloneczko
Kidprotect
Dzieci Niczyje