re: Be Careful When Copying Mutable Data Types VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Good explanation and just want to add that for copying a list in python you have a shortcut, namely my_copy = my_list[:]
 

Good point! Oddly enough, I wrote a whole article about cloning lists which includes slices as an example, so I'm not sure why I chose to use list comprehensions. I think the decision was based on the very last example which uses the copy constructor, but who knows! haha

Thanks again for the tip!

code of conduct - report abuse