Indexes are zero based. So length -1 is limit.
You can just do this instead though:
c = True
while c:
c = False
for n in x:
if n > 50:
x.remove(n)
c = True
You have the extra loop because if you don't you still end up with values over 50.
But lambdas:
x = list(filter(lambda n: n <= 50,x))
or list comprehensions are easier:
x = [n for n in x if n <= 50]
Also if you were to remove an entry from a list... it's length reduces..
So on each removal you would effectively have to re-evaluate. pop
is the Python operator to remove an entry by the index. So, you'd end up with the far more cumbersome code like this:
x = [43, 87, 23, 78, 87, 1, 3, 54]
i = 0
while i < len(x):
if x[i] > 50:
x.pop(i)
continue
i=i+1