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: Will Python 3.0 remove the global interpreter lock (GIL)
Re: Any syntactic cleanup likely for Py3? And what about doc
Re: iterator problem
Re: const in C++
Re: Templated class declaration
optymalizacja
praca za granicą
części zamienne wózki
wynajem mieszkań opole
Filmowanie ślubów
fronty mdf
kraków pizza
Bilety autobusowe do Wiednia, Londynu, Paryża
ochrona konsumenta
tresura psów porady
krwiopijstwo pospolite