Fun python 3.2 one-liner

gb gb at cabiate.it
Mon Apr 4 16:09:18 EDT 2011


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
[thanks to marco (zip(*...)) and antonio (lambda with default
arguments)]


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /