Bag
A bag (also known as a multi-set) is a unordered collection of objects, similar to a hash table, where each object has a count number, which represents the number of times it exists in the bag.
Operations
The Bag class supports all the set operators, such as intersection, difference, symmetric difference, union and concatenation.
Updating the bag
The methods bag.add_pair(obj, count)
and bag.update_pair(obj, count)
can be used for efficiently updating a bag in-place.
Furthermore, the method bag.delete(obj)
can be used for removing one occurrence of object obj
from the bag, while the .delete_all(obj)
can be used for removing all the occurrences of obj
from the bag.
Last updated