[quote="disillusioned"]I fed this: a = [7,4,5,3,6] to the following python code, and "reduce"
doesn't seem to work as I expected:
import sys
if __name__ == '__main__':
a = map(float,sys.stdin.read().split())
print a
n = len(a)
m = sum(a)/n
s = map(lambda x: x-m, a)
s = reduce(lambda x,y: x+(y**2),s)
print s
instead of calculating the sum of squares (10 in this case)
it outputs just 8.[/quote]
I think your post does not have anything to do with making Python faster.
Anyway I analysed your code briefly. Using the initialiser for reduce (3rd optional parameter) should solve your problem. Set it to 0. Also using integer is actually sufficient.