Aug-21-2019, 02:02 AM
You are modifying a list that you are looping through. Here's an idea of what is happening:
- Start at position 0 with value 1
- Remove element at position 0, all following elements are shifted back by one
- Continue at position 1 with value 3 (you skipped over 2)
- Remove element at position 1, all following elements...
- Continue at position 2 with value 5 (you skipped over 4)
- Remove element at position 2, ...
- All following elements are preserved because they do not meet the if test.
both = nums + words new_list = [] for each in both: if each not in range(1000): new_list.append(each)I haven't tested this but it should do the trick.