Home

beginner <zyzhu2000@gmail.com> writes:

> 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.

This is very 'functional' (and also quite concise):

f = compose(list,partial(unfold, divmod(_,26)))

The definitions of compose, unfold, and _ are left as excercises (of
increasing difficulty) for the reader.

'as

previous
next

Re: Any guide to look something up in the Holy Standard?
Re: I MEANT ONIX.... [it was Re: ONYX]
Re: UTF-8 characters in doctest
Re: plain iterator to vector<const int>
Re: How to insert in a string @ a index
Dowcipy Varial Info
Szalka petriego
rzeczoznawca majątkowy Oleśnica
nawigacja gps
portal-ekologia.com.pl