Skip to content
Advertisement

Modifying an item in a list of lists, changes also other lists same item position

The following code is part of a function but the problem I have is on these lines.

JavaScript

and this generates a list of lists as:

JavaScript

If for example I want to modify only the second value in the second item from the second list:

JavaScript

Is not only changing the desired value but also other lists values in the same index position.

JavaScript

What am I missing? I need that each list within a list be independent. I’m guessing that the reason is in the product of itertools but I don’t totally understand why.

What would be the solution?

Advertisement

Answer

Using json to serialize and deserialize.

JavaScript

output

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