You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A bag (multiset) can be implemented as a map of items to their frequency.
In subfolder paddles, add a file bag.py:
The file imports Iterable and Hashable from collections.abc
Create a class HashTableBag. The docstring states that it implements a bag with a hash table (Python dictionary).
The class should have methods to
add one occurrence of an item (in this and the next two methods, the item parameter is annotated with type Hashable)
remove one occurrence of an item (do nothing if the bag hasn't the item)
return the frequency of an item (0 if it's not a member of the bag)
return the size of the bag (total number of items)
return a new bag with the union of two bags
return a new bag with the intersection of two bags
return a new bag with the difference of two bags
check if two bags are equal (same items, with the same frequency)
check if one bag is included in another (each item of the first bag occurs with the same of higher frequency in the second bag)
The __init__ method takes an optional iterable collection (type annotation: Iterable[Hashable]) as argument and adds all its items to the newly created bag, with a for loop as in stack.py.
Add a docstring to each method, including the method's complexity.
Add a docstring at the start of the file, explaining what bags are. (See stack.py for the structure of the explanation.)
In subfolder tests, add a file test_bag that tests the bag's methods following the structure described in CONTRIBUTING.md.
Doing all of the above requires some effort for a single person, so you may wish to do only part of it, e.g. the code or the docstrings or the tests, and leave the other parts to others. We can give guidance on how multiple people can work on a single issue.
The text was updated successfully, but these errors were encountered:
A bag (multiset) can be implemented as a map of items to their frequency.
In subfolder
paddles
, add a filebag.py
:Iterable
andHashable
fromcollections.abc
HashTableBag
. The docstring states that it implements a bag with a hash table (Python dictionary).Hashable
)__init__
method takes an optional iterable collection (type annotation:Iterable[Hashable]
) as argument and adds all its items to the newly created bag, with a for loop as instack.py
.stack.py
for the structure of the explanation.)In subfolder
tests
, add a filetest_bag
that tests the bag's methods following the structure described in CONTRIBUTING.md.Doing all of the above requires some effort for a single person, so you may wish to do only part of it, e.g. the code or the docstrings or the tests, and leave the other parts to others. We can give guidance on how multiple people can work on a single issue.
The text was updated successfully, but these errors were encountered: