Dictionary copy : Dictionary Copy « Dictionary « Python

Dictionary copy

Dictionary copy
#The copy method returns a new dictionary with the same key-value pairs (a "shallow 
#copy," since the values themselves are the same, not copies):

x = {'username': 'admin', 'machines': ['foo', 'bar', 'baz']}
y = x.copy()
y['username'] = 'mlh'
print y

print x


Related examples in the same category

1.Copy a dictionaryCopy a dictionary
2.Dictionary deep copyDictionary deep copy