From b974426bcd5d5c3b01b743dfd4952f9d56d3a37f Mon Sep 17 00:00:00 2001 From: Prajwal <40351128+TheDaemonLord@users.noreply.github.com> Date: Thu, 3 Oct 2019 16:38:21 +0530 Subject: [PATCH] Update median.md --- snippets/median.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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