Mega Code Archive

 
Categories / Python Tutorial / Dictionary
 

Copy method returns a duplicate shallow dictionary

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