2.3 list reverse() bug?

Alex Martelli aleax at aleax.it
Sun Dec 28 00:20:48 CET 2003

Bjorn Pettersen wrote:
> ambigous when I stated it. If you look at my response to Alex, you'll see
> that I really do mean that copies are virtually never needed [in the
> aesthetic, not the Turing complete sense], and if you do use them you're

BTW, the reason copy.copy exists is to make _polymorphic_ (shallow) copies:
copying without needing to know what object you're copying.  E.g., consider:

def remove_baddies(container, badp):
    for x in copy.copy(container):
        if badp(x): del container[x]

do I hear you cringing?  OK, this code is _polymorphic_: it works just
as well whether container is a list (applies badp on the items) or a
dict (applies badp on the keys) or any other container which implements
the needed protocols (copyable, iterable, indexable by the items you
get when iterating, supports item-deletion).

Can you show us how to obtain this level of polymorphism w/o copy?

Or, don't you consider polymorphism elegant?  Personally, I do!


More information about the Python-list mailing list