By using slicing again at the next level do you mean making another copy of copy I already made? I tried doing this but it still changes the original. I'm learning Python independently using openbookproject.net. deepcopy() was suggested. I'll check it out, Thanks.
- Code: Select all
matrix_clone = matrix[:]
matrix_clone2 = matrix_clone[:]
micseydel wrote:When you use the slice, you're making a copy of the most upper list, which is good, but your newly copied list contains references to all the old lists. You need to make copies of those too. I would use copy.deepcopy() for that although you could use slicing again at the next level if this is for school and you're prohibited from using that.