Skip to content
Advertisement

List change after copy Python

I’m coding the final part of a clustering program, I want to parse a file like

JavaScript

where

JavaScript

Example:

JavaScript

I want to save all this information in different classes to process the data easier.

Here is my code in python:

JavaScript

For some reason, after the while loop, when I print all clusters objects, I see that all contains the same pixels list, I try to do a copy with deepcopy, with [:] and with list() but makes no sense. I don’t know where my error is, also I print the cluster after reset to [] and I see that is save like a reference list but I don’t know why if I use list() to make a copy.

Thanks!

Advertisement

Answer

You need Cluster instance’s attribute named pixels:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement