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}
chain1=ChainMap(d1,d2)
print (chain1)#Output:ChainMap({'a': 1, 'b': 2}, {'c': 3, 'd': 4})
#parents method will return all maps in the current instance except first one.
print (chain1.parents)#Output:ChainMap({'c': 3, 'd': 4})
d3={'e':5,'f':3}
chain2=ChainMap(d1,d2,d3)
print (chain2)#Output:ChainMap({'a': 1, 'b': 2}, {'c': 3, 'd': 4}, {'e': 5, 'f': 3})
print (chain2.parents)#Output:ChainMap({'c': 3, 'd': 4}, {'e': 5, 'f': 3})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment