When i make a new list via copy from an existing list. The changes i made to new list also reflected in the old list. How can i solve this.
I have used .copy but it failed.
# original list
prediction = [{'seriesname': 'Male', 'data': [681, 696, 711, 726, 739]},
{'seriesname': 'Female', 'data': [101, 104, 107, 109, 112]}]
# make a copy
prediction_percentages = prediction.copy()
# test to check the 2 objects are different
prediction_percentages is prediction
False
# Make a change in new list
prediction_percentages[0]["data"][0] = 1111
# now the changes appear in old list also
prediction_percentages
[{'seriesname': 'Male', 'data': [1111, 696, 711, 726, 739]},
{'seriesname': 'Female', 'data': [101, 104, 107, 109, 112]}]
prediction
[{'seriesname': 'Male', 'data': [1111, 696, 711, 726, 739]},
{'seriesname': 'Female', 'data': [101, 104, 107, 109, 112]}]
The final result should be
prediction_percentages
[{'seriesname': 'Male', 'data': [1111, 696, 711, 726, 739]},
{'seriesname': 'Female', 'data': [101, 104, 107, 109, 112]}]
prediction
[{'seriesname': 'Male', 'data': [681, 696, 711, 726, 739]},
{'seriesname': 'Female', 'data': [101, 104, 107, 109, 112]}]