Method Name:
update
Method Signature:
update(itearableObjectOrMappingObject)
Method Overview:
- update() is like the add() counterpart of the subtract method.
- update() takes a python iterable object or a mapping object and adds the counts of elements present in the iterable/mapping object to the counts of elements present in the counter object.
Example:
import collections
counterObject = collections.Counter({"z":9,"y":8,"x":7}) print("Counter object before update:") print(counterObject) counterObject.update({"z":1,"y":2}) print("Counter object after update:") print(counterObject) |
Output:
Counter object before update: Counter({'z': 9, 'y': 8, 'x': 7}) Counter object after update: Counter({'z': 10, 'y': 10, 'x': 7}) |