On Mar 28, 2:25 am, Andrea Crotti <andrea.crott...@gmail.com> wrote: > John Ladasky <lada...@my-deja.com> writes: > I almost never use them either, maybe also in many cases you could avoid > using them... > When for example you use them?
To take one example: neural network programming. I construct a network object (which is quite complex), test it, and keep it. Next, I copy the network object, apply a slight variation to it, and test that. If the variant performs less well than the original, I discard the variant, and try another slightly-varied copy of the original. If the variant is superior, I discard the original. And so on. Another use: When I'm profiling code for speed, I generate a sequence of function calls in a specific order. I would like to retain that ordered sequence for when I print out the results of my speed test, but also generate shuffled variations of that sequence. But random.shuffle() alters the sequence in place, it does not return a copy. If shuffle() did return a copy, I would not need to invoke copy myself, but that's how the library function is written. > 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. That may be, but when it already takes several seconds for my neural network object to compute the output from a 100-element input sequence, the time that the occasional deepcopy call takes is insignificant to me. -- http://mail.python.org/mailman/listinfo/python-list