fork download
  1. def median(listof):
  2. listof = sorted(listof)
  3. if len(listof) % 2 == 1:
  4. return listof[len(listof)//2]
  5. else:
  6. middleposition1 = listof[len(listof)//2-1]
  7. middleposition2 = listof[len(listof)//2+1]
  8. Median = (middleposition1 + middleposition2)/2
  9. return Median
  10. print(median([4, 5, 5, 4]))
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
4.5