How to modified values of dictionaries through ChainMap in Python

1 Answer

0 votes
import collections     
 
d1 = {'a': 'AA', 'c': 'CC', 'd': 'EE'}
d2 = {'b': 'BB', 'c': 'DD', 'f': 'GG'}     
  
cm = collections.ChainMap(d1, d2)     
 
cm['AA'] = 'PYTHON' 
cm['DD'] = 'PHP' 
 
print(format(cm['AA']))
print(format(cm['DD']))

print(d1)
print(d2)
 
 
 
'''
run:
 
PYTHON
PHP
{'a': 'AA', 'c': 'CC', 'd': 'EE', 'AA': 'PYTHON', 'DD': 'PHP'}
{'b': 'BB', 'c': 'DD', 'f': 'GG'}
 
'''

 



answered May 3, 2019 by avibootz

Related questions

1 answer 175 views
1 answer 138 views
3 answers 226 views
1 answer 106 views
4 answers 223 views
...