Given a list of integers how would I remove all values greater than a given value, it seems to work with all values except for one. I know this is an issue probably an issue of changing the length of the list while I'm iterating through it but I just cant figure out where the issue is.
nums = [100,2,7,11,13,15]
target = 9
for x in nums:
if x > target:
nums.remove(x)
print(nums)
Returns:
[2, 7, 13]
Why not
[2, 7]