Fun python 3.2 one-liner

Chris Angelico rosuav at gmail.com
Mon Apr 4 17:46:39 EDT 2011


On Tue, Apr 5, 2011 at 6:09 AM, gb <gb at cabiate.it> wrote:
> harrismh777 <harrismh777 at charter.net> writes:
>
>> Seriously, these little one liners teach me more about the python
>> language in less time than [...]
>
> def f(x,n,w): return x if n==1 else\
>    (lambda x0=f(x[::2],n/2,w[::2]),\
>            x1=f(x[1::2],n/2,w[::2]): reduce(lambda a,b: a+b ,\
>                                      zip(*[(x0[k]+w[k]*x1[k],\
>                                             x0[k]-w[k]*x1[k])\
>                                             for k in range(n/2)])))()
>
> it was a joke of sort played on it.comp.lang.python

(Remind me how it is that Python code is more readable than line noise
or Perl code?)

What sort of parameters does this take? So far all I can figure out is
that n is an integer and x and w are sliceables, but I'm not sure
whether x and w should be strings or arrays.

ChrisA



More information about the Python-list mailing list