Sep-16-2023, 12:52 PM
(This post was last modified: Sep-16-2023, 12:52 PM by deanhystad.)
Do not use "list" as a variable name. list() is a built-in function that creates a list.
There are no "static" variables in Python. "total" is a class variable.
Your problem is here:
There are no "static" variables in Python. "total" is a class variable.
Your problem is here:
p_data=list[i].datap_data and list[1].data are the same list object. Even though "data" is an instance variable that references a list, all instances of Node end up referencing the same list object. Do you want each node to have their own list? You could do this:
p_data=list[i].data.copy()Now p_data and list[1].data are different lists. They have the same contents, but they are different list objects. When you create a new Node using pdata, the data in the old Node and the new Node will be different lists.