dev = math.sqrt(sum([t*t for t in samples])/N - avg * avg)

is shorter, then you don't need varsum