Copying contents of one dictionary to another dictionary

Copying contents of one dictionary to another dictionary

Contents of one dictionary can be copied to another using the copy() function.

name = {1:"TalentEve",2:"Embeddeddesignblog",3:"YouTube-Way2Know",4:"Myvision-thisworld",5:"forum.TalentEve.com"}

name_1 = name.copy()

print(name_1)

-------------------

Contents can be copied to another dictionary using a simple assignment operator as we do with variables

name = {1:"TalentEve",2:"Embeddeddesignblog",3:"YouTube-Way2Know",4:"Myvision-thisworld",5:"forum.TalentEve.com"}

name_2 = name_1

print(name_2)

-------------------

while the copy() function and assignment operator in above two cases perform the same functionality, copy() creates a new dictionary while the assignment operator points to the same dictionary

Post a Comment

0 Comments