Skip to content
Snippets Groups Projects
Commit 55cc8ff0 authored by Marco Biasini's avatar Marco Biasini
Browse files

added Median function

parent af7354df
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,7 @@ def Median(xs): ...@@ -56,7 +56,7 @@ def Median(xs):
raise RuntimeError("Can't calculate median of empty sequence") raise RuntimeError("Can't calculate median of empty sequence")
sorted_xs=sorted(xs) sorted_xs=sorted(xs)
if (len(xs) % 2)==0: if (len(xs) % 2)==0:
return (sorted_xs[len(xs)/2]+sorted_xs[len(xs)/2]+1)/2 return (sorted_xs[len(xs)/2]+sorted_xs[len(xs)/2+1])/2
else: else:
return sorted_xs[len(xs)/2] return sorted_xs[len(xs)/2]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment