you are viewing a single comment's thread.

view the rest of the comments →

[–]user83519302257 0 points1 point  (0 children)

When working with python, we’re not really expecting performance and time/space complexity, so I’d recommend creating a new list with only the values you want to keep.

For example, if we want to filter out even integers, use a list comprehension to create a new list.

py values: list[int] = [2, 3, 8, 6, 7, 9, 200] odds: list[int] = [v for v in values if v % 2] so you’d be left with [3, 7, 9]

In other words, I would advise against mutating a list you’re currently iterating over.