Update median.md

This commit is contained in:
Angelos Chalaris
2019-10-04 09:13:50 +03:00
committed by GitHub
parent 48fe457f6f
commit b3b895cb67

View File

@ -2,6 +2,7 @@
title: median
tags: math,beginner
---
Finds the median of a list of numbers.
Sort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even.
@ -15,6 +16,7 @@ def median(list):
else:
return list[int(list_length/2)]
```
```py
median([1,2,3]) # 2
median([1,2,3,4]) # 2.5