How to use ChainMap to reverse a list of 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)    

cm.maps = list(reversed(cm.maps))

print(cm.maps)

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

'''

 



answered Apr 30, 2019 by avibootz
...