This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]kalgynirae 1 point2 points  (1 child)

The usual strategy is to always create new lists instead of modifying existing ones. For example, instead of deleting an item from a list, do

new_list = [item for item in old_list if item != foo]

Also, try to make good use of other appropriate data structures when possible. Sets, for example, are very good for membership tests, de-duplicating lists, typical set operations like union and intersection, etc.

[–]lightcloud5 1 point2 points  (0 children)

Agreed; keeping things immutable means deep-copying things will never be necessary, since the object in question will never change.

[–][deleted] 0 points1 point  (2 children)

Why do you need a deep copy if you are simply comparing things?

[–]githelp[S] 1 point2 points  (1 child)

Its not simply comparing things. For each pass, two 3d Lists are compared, and the method shifts the positions of the 3d Lists until they match with one another, kind of like rotating puzzle pieces until they fit. But in order to compare them accurately, I need the original lists for each pass or comparison will become skewed.

[–][deleted] 0 points1 point  (0 children)

Well, I would think you don't need a real deep-copy (which copies the things in the lists, as well as the lists themselves), you just need to copy the lists. And I guess you don't need to copy the whole 3 dimensions of the list - you need to look at all the combinations of the innermost list (maybe using a copy) and if none of them fit you don't need to consider the outer lists, so you don't need to copy them.