-
-
Save IndhumathyChelliah/9265721df5bd5c0427ad998e6dd50e16 to your computer and use it in GitHub Desktop.
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 Counter | |
c1=Counter({'a':2,'b':1,'c':4,'d':3}) | |
c2=Counter({'a':3,'b':5,'e':7}) | |
#update() method in Counter object add the count of elements | |
c1.update(c2)#Output:Counter({'e': 7, 'b': 6, 'a': 5, 'c': 4, 'd': 3}) | |
print (c1) | |
#dict update | |
#Update() method adds elements to the dictionary if key is not in that dictionary. If key is in the dictionary means, it will update the new value. | |
d1={'a':2,'b':1,'c':4,'d':3} | |
d2={'a':3,'b':5,'e':7} | |
d1.update(d2) | |
print (d1)#Output:{'a': 3, 'b': 5, 'c': 4, 'd': 3, 'e': 7} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment