Billy Mays <no...@nohow.com> writes: > I'm trying to shorten a one-liner I have for calculating the standard > deviation of a list of numbers. I have something so far, but I was > wondering if it could be made any shorter (without imports).
> a=lambda d:(sum((x-1.*sum(d)/len(d))**2 for x in d)/(1.*(len(d)-1)))**.5 You should make it two half-liners, because this one repeatedly computes sum(d). I would suggest: aux = lambda s1,s2,n: (s2 - s1*s1/n)/(n-1) sv = lambda d: aux(sum(d),sum(x*x for x in d),len(d)) (after some algebra). Completely untested, assumes data come in as floats. You get the idea. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list