Skip to content

Instantly share code, notes, and snippets.

@pielgrzym
Created November 16, 2013 19:34
Show Gist options
  • Save pielgrzym/7504315 to your computer and use it in GitHub Desktop.
Save pielgrzym/7504315 to your computer and use it in GitHub Desktop.
def mean(Z):
def sr(x, y):
cnt = x[1] + 1
return x[0]+y, cnt, (x[0]+y)/cnt
return reduce(sr, Z, [0,0,0])[2]
assert mean([1,2,3]) == 2
assert mean([1.5, 2.5, 3.5]) == 2.5
assert mean([1]) == 1
assert mean([-2.0, 2.0, 0.0]) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment