Could anyone tell me why this isn't working? I got error saying:
ValueError: list.remove(x): x not in list
.
But if I try print max
; it prints 9,
and also if I print min
; it prints 1.
list = [3,1,4,9,5,7]
max = list[0]
min = list[0]
list = list[:]
while len(list)> 2:
for i in list:
if(i > max):
max = i
elif(i < min):
min = i
list.remove(min)
list.remove(max)
print list
I need to remove max and min element from list, until there are only 2 elements in order to get the median of the list.