Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 9, 2020 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/b5f398a751e00f1a683c435a6f0758e1 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/b5f398a751e00f1a683c435a6f0758e1 to your computer and use it in GitHub Desktop.
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