list IndexError

Grant Edwards grante at visi.com
Thu Dec 23 17:28:50 CET 2004


On 2004-12-23, Steven Bethard <steven.bethard at gmail.com> wrote:

>> Ah, my mistake, I missed the [:] after the source argument
>> that was taking a copy... which brings up the question, how
>> many other people would miss it?
>
> Too many.  This is why I greatly prefer
>
>     list(lst)

To me, that's just as non-obvious.  I would have guessed that
calling list() on a list was a noop.  I would be wrong.
Surprised, but wrong.

> to
>
>     lst[:]
>
> It's also clearer to me.  Do I really want a "slice" of the
> list?  No, I want a list copy of the list...

Wouldn't the clearest way to get a copy would be to do
something like:

   copy(lst)   # I still think copy.copy() is a bit verbose...
or 
   lst.copy()  # doesn't exist, but I think it should :)

-- 
Grant Edwards                   grante             Yow!  I had pancake makeup
                                  at               for brunch!
                               visi.com            



More information about the Python-list mailing list