I've got this code:
numbers = list(range(1, 50))
for i in numbers:
if i < 20:
numbers.remove(i)
print(numbers)
This code should go through all the elements of the list and remove those elements that are less than 20. But, the result I'm getting is:
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
As you can see, the code removed all even numbers less than 20, but left the odd ones. Looks like I'm doing something wrong with the remove.