Welcome Guest, Not a member yet? Register   Sign In
Problem with Dictionary Copies
#1

Hello there,

I'm new to this and trying to make a clone of a dictionary so that I may make changes without harming the original, as I learnt from scaler's post. However, even after making the copy, the modifications I make appear to have an effect on both the copy and the original dictionary. This is my code:
Code:
original_dict = {'x': 1, 'y': 2, 'z': 3}
copy_dict = original_dict

copy_dict['x'] = 100

print("Original Dictionary:", original_dict)
print("Copy Dictionary:", copy_dict)

Surprisingly, both dictionaries exhibit the same 'x' value. I thought I'd made a separate duplicate, but it appears that modifications to one are affecting the other. How can I actually make a duplicate of the dictionary?
Reply
#2

Forum PHP for programmers) There may be no answer
Simple CI 4 project for beginners codeigniter-expenses
Reply




Theme © iAndrew 2016 - Forum software by © MyBB