pythonize this!

Xavier Ho contact at xavierho.com
Tue Jun 15 08:06:16 EDT 2010


On 15 June 2010 21:49, superpollo <utente at esempio.net> wrote:

> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>

Obligatory one-liner:

>>> sum((1, 1, 1, -1, -1)[(x-1) % 5] * x**2 for x in xrange(1, 2011))
536926141

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100615/1357b80b/attachment-0001.html>


More information about the Python-list mailing list