What is the "functional" way of doing this?

James Stroud jstroud at mbi.ucla.edu
Tue Jul 31 03:13:58 CEST 2007


James Stroud wrote:

> py> f = lambda n, r=None: f(n/26, (r if r else [])) + [n%26] if n/26 
> else [n%26]
> py> f(300000)
> [17, 1, 20, 12]
> py> f(30000)
> [1, 18, 9, 22]
> py> f(3000)
> [4, 11, 10]
> py> f(1000)
> [1, 12, 12]
> 
> 

Oops, those are backwards. Should be:

f = lambda n, r=None: [n%26] + f(n/26, (r if r else [])) if n/26 else [n%26]

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

http://www.jamesstroud.com/



More information about the Python-list mailing list