Why aren't copy and deepcopy in __builtins__?

Dave Angel davea at ieee.org
Mon Mar 28 06:55:30 EDT 2011


On 01/-10/-28163 02:59 PM, Andrea Crotti wrote:
> John Ladasky<ladasky at my-deja.com>  writes:
>
>> Simple question.  I use these functions much more frequently than many
>> others which are included in __builtins__.  I don't know if my
>> programming needs are atypical, but my experience has led me to wonder
>> why I have to import these functions.
>
> I almost never use them either, maybe also in many cases you could avoid
> using them...
> When for example you use them?
>
> I noticed some time ago in a program that needed speed that deepcopy in
> particular is incredibly slow, but I guess is normal since it has to
> copy every bit of the data structure.
>

I'd expect it to be very slow.  I presume it not only has to visit and 
duplicate every bit of the data structure, but also has to detect loops, 
and avoid infinite loops recreating them.

This loop detection is probably an n-squared algorithm, so it grows much 
faster than the number of items being deep-copied.

DaveA



More information about the Python-list mailing list