Question: The remove ( ) method resizes the array when necessary by removing an item from the array if it exist Be sure to reuse your
The remove method resizes the array when necessary by removing an item from the array if it exist
Be sure to reuse your solution from Programming Exercise as your starter file for the arraybag.py file.
In the arraybag.py file define the remove method in the ArrayBag class by completing the following:
Check the precondition and raise a KeyError if necessary
Precondition: item is in self.
Raises: KeyError if item in not in self.
Postcondition: item is removed from self.
Search for the index of the target item
Shift items to the left of target up by one position
Decrement logical size
Check array memory here and decrease it if necessary
To test your program run the testResize method in the testbag.py file.
Added items, length of bag
Expect as length of array
Removed items, expect as length of bag:
Expect as length of array
Removed remaining items, length of bag
Expect as length of array
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
