I'm trying to make a list of 11 elements
I want to pop out the maximum element only from l[0]
to l[5]
. under one of the two conditions:
l[5] >= 3
or l[5]
is no longer exist or None
.
l = [2,8,6,2,8,7,9,8,6,7,4]
max = 0
maxIndex = 0
while (l[5] >= 3 or l[5] is None):
for x in range(6):
if l[x] > max:
max = l[x]
maxIndex = x
l.pop(maxIndex)
print(l)
I am getting the error:
IndexError: list index out of range
I know at some point l[5]
will no longer exist, but how can I create this code.