I encountered the following problem: I have a list of numbers and a maximal value. I want to exclude all values in num that are greater than the given max. I wrote two loops that should be able to do so:
num=[0.5,1,1.5,2]
max=0.5
for eachNum in num:
if eachNum>max:
num.remove(eachNum)
i=0
while i<len(num):
if num[i]>max:
num.pop(i)
i=i+1
Both loops failed. They left the 1.5 in the list and I do not get why. Any help greatly appreciated.