Median


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096#


The code works, but is it any good? Or is the code way to complecated? I am a little bit sceptical


def median (numlist):
    sl = sorted(numlist)
    indexmid = (len(numlist)-1)/2
    indexodd1 = len(numlist)/2
    indexodd2 = (indexodd1)-1
    if len(numlist)%2 == 0:
        return ((sl[indexodd1] + sl[indexodd2]) / 2.0)
    else:
        return sl[indexmid]
        
liste= [1,4,3,2,5,7,6]
print median(liste)


#2

Maybe with a google search, you'll find discussions/opinions
python median from list site:stackoverflow.com


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.