Copy Dictionaries

 

Copy Dictionaries

We can use the copy() method to copy the contents of one dictionary into another dictionary.


Example:

info = {'name':'Maxon', 'age':25, 'eligible':True, 'DOB':1999}
newDictionary = info.copy()
print(newDictionary)

Output:

{'name': 'Maxon', 'age': 25, 'eligible': True, 'DOB': 1999}

 

Or we can use the dict() function to make a new dictionary with the items of original dictionary.


Example:

info = {'name':'Maxon', 'age':25, 'eligible':True, 'DOB':1999}
newDictionary = dict(info)
print(newDictionary)

Output:

{'name': 'Maxon', 'age': 25, 'eligible': True, 'DOB': 1999}