DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

Posted on

Updating Map in Python

when the element of the dictionary is updated, the result is instantly updated in the result of the ChainMap, Enter the below code and try to execute it to see how updating Maps is done.

import collections

dict1 = {"player1":'cole palmer',"player2":'Raheem Sterling',"player3":'Reece james'}
dict2  = {"player4":'Levi Colwil',"player5":'Moises Caicedo',"player6":'Conor Callagher'}

res  = collections.ChainMap(dict1,dict2)
print(res.maps, '\n')


dict2['player4'] = 'Noni Madueke'
print(res.maps, '\n')
Enter fullscreen mode Exit fullscreen mode

output
When the above code is executed, it produces the following result .

[{'player1': 'cole palmer', 'player2': 'Raheem Sterling', 'player3': 'Reece james'}, {'player4': 'Levi Colwil', 'player5': 'Moises Caicedo', 'player6': 'Conor Callagher'}] 

[{'player1': 'cole palmer', 'player2': 'Raheem Sterling', 'player3': 'Reece james'}, {'player4': 'Noni Madueke', 'player5': 'Moises Caicedo', 'player6': 'Conor Callagher'}]
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more