Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 9, 2020 06:38
Show Gist options
  • Save IndhumathyChelliah/3b08ac03a207469ee515b31ff1192188 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/3b08ac03a207469ee515b31ff1192188 to your computer and use it in GitHub Desktop.
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