Chalarangelo / 30-seconds-of-python

Short Python code snippets for all your development needs
https://www.30secondsofcode.org/python/p/1
Creative Commons Attribution 4.0 International
8.83k stars 1.26k forks source link

Inconsistent return type of `median` function for odd and even length of list #219

Closed azanbinzahid closed 4 years ago

azanbinzahid commented 4 years ago

The return type of median function is int for odd length list and float for even length list.

Current Example:

median([1, 1, 1])  # 1 (int)
median([1, 1, 1, 1])  # 1.0 (float)

It can be made consistent by returning float value in case of odd length as well if needed.