Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def median(lst):
- if type(lst)==list:
- lst=sorted(lst)
- count=len(lst)
- if count%2==0:
- index_1 = len(lst)/2 - 1
- index_2 = len(lst)/2
- #left=lst[count/2 - 1]
- #right=lst[count/2]
- return (lst[index_1] + lst[index_2])/2.0
- else:
- index = len(lst)//2
- return lst[index]
- print (median([2, 4, 5, 9]))
Add Comment
Please, Sign In to add comment