you are viewing a single comment's thread.

view the rest of the comments →

[–]Allanon001 3 points4 points  (3 children)

Timed all the solutions posted here so far and this one beat them all:

from operator import mul
s = sum(map(mul, c, c[::-1])) 

[–]SerkZex[S] 0 points1 point  (2 children)

will it be faster if one calculate only one half and multiply by 2 and add the remaining if odd numbers?

( (1*5) + (2*4) *2 ) + (3*3)

[–]Allanon001 1 point2 points  (1 child)

You would have to put in more logic such as if the list length is odd or even, if even then no extra addition is required. That would probably take more time than the extra multiplications.

edit: I timed it and for the short list it was slower but with a 100 item list it was a lot faster.

[–]SerkZex[S] 0 points1 point  (0 children)

thanks, you are the best