[ create a new paste ] login | about

Link: http://codepad.org/ds0rMNlC    [ raw code | output | fork ]

jonlyles - Python, pasted on Nov 9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
num_list=[4,5,5,4]

num_list = sorted(num_list)
print num_list

if len(num_list) % 2 != 0:
  print "odd list"
  middle = (len(num_list)/2)
  median = num_list[middle]
else:
  print "even list"
  print len(num_list)
  median = (num_list[ (len(num_list) / 2) ] + num_list[ (len(num_list) / 2)-1 ])
  median = float(median) / 2
  
print median


Output:
1
2
3
4
[4, 4, 5, 5]
even list
4
4.5


Create a new paste based on this one


Comments: