Arnaud Delobelle wrote:
> def unit(v):
> return map((sum(map(lambda x:x*x, v))**0.5).__rdiv__, v)
>
> The hard bit was to make it less readable than the Ruby version ;)
I loved the use of __rdiv__ :)
I would have proposed the more straightforward:
def u(v):
return [x/sum(x**2 for x in v)**0.5 for x in v]
or, in order to avoid computing the norm for each element:
def u(v):
return (lambda norm: [x/norm for x in v])(sum(x**2 for x in v)
**0.5)
--
Roberto Bonvallet
--
http://mail.python.org/mailman/listinfo/python-list