(Jun-14-2019, 06:50 PM)calonia Wrote: modifying a list while iterating through it(adding or removing items) leads to skipping indexes.You should know that you can loop over a copy of a list however
The [:] returns a shallow copy of the list, in which this case doesnt matter because all of the elements are ints
numbers = [3, 3, 20, 6, 10, 6, 5, 5, 7, 10, 7, 19, 19, 20] for x in numbers[:]: if numbers.count(x) > 1: numbers.remove(x) print(numbers)
Output:[3, 6, 5, 10, 7, 19, 20]
Recommended Tutorials: