Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 9, 2020
Embed
What would you like to do?
from collections import ChainMap
d1={'a':1,'b':2}
d2={'c':3,'d':4}
chain=ChainMap(d1,d2)
print (chain)#Output:ChainMap({'a': 1, 'b': 2}, {'c': 3, 'd': 4})
#maps attribute will return list of mappings
d3=chain.maps
print (d3)#Output:[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]
#Return type is List
print (type(d3))#Output:<class 'list'>
#performing list methods
d3=chain.maps
print (list(reversed(d3)))
#printing the keys
print (list(chain.keys()))#Output:['c', 'd', 'a', 'b']
#printing the values
print (list(chain.values()))#Output:[3, 4, 1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment