[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Concerning copy



On 4/27/06, Kamilche <klachemin@xxxxxxxxxxx> wrote:
> That's not good. It's misleading the programmer into thinking
> divisibility by 2 is an important criterion. What if it was a list of
> objects instead of numbers, and not divisible at all?

I think the point was to demostrate some situation where list items
are removed according to certain criterion (in this case,
divisibility). If you are removing every item, you wouldn't use a loop
at all. You would just call

del nums[:]

which removes every item from the list (but of course doesn't delete
the items themselves if there still are references elsewhere).

This whole thing got a bit sidetracked. The point was that everyone
should just rember that if you iterating over a container, you
shouldn't mutate that container at the same time, but rather iterate
over a temporary copy to prevent weird side-effects.

--
Sami Hangaslammi