This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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