Python deepcopy any alternatives?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
PeteP
What the peck?
Posts: 1451
Joined: Tue Aug 23, 2011 4:51 pm UTC

Python deepcopy any alternatives?

Postby PeteP » Mon Sep 07, 2015 10:03 pm UTC

I'm relatively new to python and I suspect it's deepcopy that is slowing down my code. I have a list of lists where the lists contain int and two further list which also contain ints. A simple enough structure. I tested iterating over it myself and copying the ints by hand and the two innermost list with extend and it seems significantly faster. From what I read only it's because deepcopy is able to handle more complex structures but is there some function for creating deepcopies of simple nested structures a bit faster?

User avatar
roflwaffle
Posts: 360
Joined: Wed Jul 01, 2009 6:25 am UTC

Re: Python deepcopy any alternatives?

Postby roflwaffle » Tue Sep 08, 2015 5:01 pm UTC

A quick search brings up this function...

https://writeonly.wordpress.com/2009/05 ... mple-data/

Apparently deepcopy can handle odd situations like objects that contain themselves, so as long as you don't have any of those situations I imagine you could use the "deepish_copy" function.

http://stackoverflow.com/questions/3043 ... it#3043961


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 6 guests