2.3 list reverse() bug?

Arthur ajsiegel at optonline.com
Fri Dec 26 15:37:56 CET 2003

On Fri, 26 Dec 2003 13:14:24 GMT, Alex Martelli <aleax at aleax.it>

>Bjorn Pettersen wrote:
>   ...
>> There are of course times where a copy is needed (e.g. multi-version
>> scenarios) but most programmers don't bump into these very frequently...
>Here's my candidate for "most frequent scenario where copies are needed":
>for item in somelist:
>    if froobable(item):
>        somelist.append(frooble(item))
>    elif uncadable(item):
>        somelist.remove(item)
I got bit by this early on. 

There are many bites to be had in the learning process. 

But I agree that this is about the only time I felt the bite was *it*,
not me. A pitfall waiting to happen.  Although I don't think I truly
understood the implications of mutability until I fell into it. 

But this is also my approach, I guess. Not exactly writing Universe
Critical code, I tend to proceed with a light reading of the docs, and
learn by having my naive intuitions corrected - as necessary when
necessary, by finding something broken.

But there is I feel a valid point implicit in my original question.  

The "I have been using Python 42 years and never imported copy" is a
very ambiguous assertion,made time and again.  One can be routinely
using copies of lists and dict without ever importing copy, since
there are adequate built-in ways of making those copies, and the copy
method itself (I am never sure why or convinced it is for the best) is
not a built-in.

The assertion about copy being "overused"  or potentially overused,
can mean very different things in different contexts, as I think the
early part of this thread clearly demonstrates.

Don't we need to pick one meaning for that assertion? Or make the
meaning clear, when asserted.


More information about the Python-list mailing list