On Mon, 30 Jul 2007 22:48:10 +0000, beginner 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.
Seems like a perfectly good function to me :)
I don't know about "functional", but that's crying out to be written as a
generator:
def f(n):
while n > 0:
n, x = divmod(n, 26)
yield x
And in use:
>>> for x in f(1000):
... print x
...
12
12
1
>>> list(f(1000))
[12, 12, 1]
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list