How to use ChainMap to manages multiple dictionaries 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)    

print(cm.maps)

    
      
'''
run:
  
[{'a': 'AA', 'c': 'CC', 'd': 'EE'}, {'b': 'BB', 'c': 'DD', 'f': 'GG'}]

'''

 



answered Apr 30, 2019 by avibootz
...