pythonize this!

Alessandro [AkiRoss] Re akirosspower at gmail.com
Wed Jun 16 06:46:18 EDT 2010


On Jun 15, 2:37 pm, Peter Otten <__pete... at web.de> wrote:
> >>> from itertools import cycle, izip
> >>> sum(sign*i*i for sign, i in izip(cycle([1]*3+[-1]*2), range(1, 2011)))

Wow!! :D
I didn't knew cycle, great! With that i can reduce my solution (which
isn't still elegant as your) to:

print reduce(add,imap(mul, cycle([1, 1, 1, -1, -1]), (v**2 for v in
xrange(1, 2011))))

(536926141)
~Aki



More information about the Python-list mailing list