[Python-ideas] Have list/deque grow a copy() method

Steven Bethard steven.bethard at gmail.com
Tue May 15 17:48:13 CEST 2007


On 5/15/07, Fred L. Drake, Jr. <fdrake at acm.org> wrote:
> On Tuesday 15 May 2007, Ian D. Bollinger wrote:
>  > It would be nice if containers had a more consistent interface. The
>  > standard idiom for copying a list has been L[:], but this isn't
>  > polymorphic and perhaps arcane. Also, deques can only be copied with the
>  > copy module's copy function (or calling the __copy__ wrapper directly);
>  > thus using copy.copy is the only polymorphic way to copy a mutable
>  > container. Additionally, having a consistent interface for mutable
>  > containers may dovetail with the ABC PEP.
>
> copy.copy() and copy.deepcopy() have always been the only polymorphic ways to
> create copies.

For builtin container types (and many other container types as well):
    type(obj)(obj)
is another polymorphic way to create copies.

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy



More information about the Python-ideas mailing list