list.remove for Novices

Tim Peters tim.one at home.com
Sun Nov 25 22:02:52 CET 2001


[Arthur Siegel]
> I see that my -
>
> >>>foo = [1, 2, 3, 4, 5]
> >>>for bar in foo:
> ...        foo.remove(bar)
>
> issue which I ran into trying to follow suggestions for
> my permutations problem was addressed beginning at:
>
> <mailman.1002041942.4167.python-list at python.org>

That looks like an email address; it's unclear what it refers to.

> But damn it to hell. Even when I try to be a normal Python
> guy, and just post up "technical" problems, I get into-
> or raise - issues/controversary.
>
> Because I am being asked to accept that the list.remove
> behavior is somehow apparent - rather than a true
> trap for the novice.

I expect every newbie gets bit by this at least once.  This is the first
time I've seen it called "apparent", though (nobody actually said that,
right?).  It's a subtlety, as the Reference Manual points out in a bold
Warning.  If you mutate a container while traversing its contents, every
language supporting such a thing does something that will surprise someone
(can't help it -- some people will be surprised if their mutations aren't
visible during the traversal, while others will be surprised if they are,
and the rest will complain if you raise an exception).

> At the same time I'm being told that I can't be expected to be able
> to handle 1/4=0 -  though that behavior is clearly documented and
> shared with many other languages.

No, you personally are expected to handle 1/4==0 just fine <wink>.

> Wish I could be hooked up to electrodes which
> would read-out the *real* issues a novice faces
> with Python.  Because I have to accept that the
> desire to address those issues is real, just often
> being based on misinformation.

"Learning Python" is an excellent source, because at the end of each chapter
the authors summarize the most frequent mistakes that popped up while
teaching the chapter's material.





More information about the Python-list mailing list