diff --git a/snippets/median.md b/snippets/median.md index d09484f66..d9b0481ad 100644 --- a/snippets/median.md +++ b/snippets/median.md @@ -1,6 +1,6 @@ --- title: median -tags: math,median,beginner +tags: math,beginner --- Finds the median of a list of numbers. @@ -11,12 +11,10 @@ def median(list): list.sort() # The sort function of python list_length = len(list) if list_length%2==0: - return (list[int(list_length/2)-1] + list[int(list_length/2)])/2 # Mean of the middle two elements + return (list[int(list_length/2)-1] + list[int(list_length/2)])/2 else: - return list[int(list_length/2)] # The element in the middle - + return list[int(list_length/2)] ``` - ```py median([1,2,3]) # 2 median([1,2,3,4]) # 2.5