By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Deletion of orginal Dict data

100+
P: 440
Hi,

I would like to retain the orginal dictionary data without deleting the entire data in it as shown below.

Expand|Select|Wrap|Line Numbers
  1. Sample
  2. >>> d1 = {1:100,2:200,3:400}
  3. >>> d2 = d1
  4. >>> d1
  5. {1: 100, 2: 200, 3: 400}
  6. >>> d2
  7. {1: 100, 2: 200, 3: 400}
  8. >>> del d2[2]
  9. >>> d2
  10. {1: 100, 3: 400}
  11. >>> d1
  12. {1: 100, 3: 400}
  13. >>> 
  14.  
But I want d1 = {1:100,2:200,3:400} to be reatined with all the values upto the end of the program.

Could you please suggest what is steps to be followed to retain the values in orginal Dict.

Thanks
PSB
Apr 30 '07 #1
Share this Question
Share on Google+
2 Replies


100+
P: 440
Please ignore this post.

I got the solution. It is copy method we have to use

d2 = d1.copy()

-PSB
Apr 30 '07 #2

bartonc
Expert 5K+
P: 6,596
Please ignore this post.

I got the solution. It is copy method we have to use

d2 = d1.copy()

-PSB
Now you're getting to be a Pythoneer!
Apr 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.