python how to find the median of a list

Posted by user3450574 on Stack Overflow See other posts from Stack Overflow or by user3450574
Published on 2014-06-07T21:04:05Z Indexed on 2014/06/07 21:24 UTC
Read the original article Hit count: 205

Filed under:
|
|
|

I'm trying to write a function named median that takes a list as an input and returns the median value of the list.

I'm working with Python 2.7.2

The list can be of any size and the numbers are not guaranteed to be in any particular order.

If the list contains an even number of elements, the function should return the average of the middle two.

This is the code I'm starting with:

def median(list):

print(median([7,12,3,1,6,9]))

© Stack Overflow or respective owner

Related posts about python

Related posts about list