Guest User

Untitled

a guest
Jun 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. def median(lst):
  2. if type(lst)==list:
  3. lst=sorted(lst)
  4. count=len(lst)
  5. if count%2==0:
  6. index_1 = len(lst)/2 - 1
  7. index_2 = len(lst)/2
  8. #left=lst[count/2 - 1]
  9. #right=lst[count/2]
  10. return (lst[index_1] + lst[index_2])/2.0
  11. else:
  12. index = len(lst)//2
  13. return lst[index]
  14.  
  15.  
  16. print (median([2, 4, 5, 9]))
Add Comment
Please, Sign In to add comment