list=[5, 14, 98, 55] i=0 for x in list: if x%5 != 0: list.remove(x) print(list) Only 14 gets deleted, while 98 stays in the list... By now I've tried anything really...
Asked
Active
Viewed 32 times
1 Answers
1
Give this a try. It creates a new list which only contains numbers divisible by 5.
listx=[5, 14, 98, 55]
newlistX = [x for x in listx if x % 5 == 0 ]
print(newlistX)

Buddy Bob
- 5,829
- 1
- 13
- 44