count(self, value: object) -> int: This method counts the number of elements in the bag that match the provided ‘value’ object. Example #1: bag = Bag…

  

Image transcription textcount(self, value: object) -> int: This method counts the number of elements in the bag that match theprovided “value” object. Example #1: bag = Bag ( [1, 2, 3, 1, 2, 2]) print (bag, bag . count (1) , bag .count (2) , bag . count (3) , bag . count (4) ) Output: BAG: 6 elements. [1, 2, 3, 1, 2, 2] 2 3 1 0… Show moreclass DynamicArrayException(Exception): “”” Custom exception class to be used by Dynamic Array DO NOT CHANGE THIS CLASS IN ANY WAY “”” passclass DynamicArray: def __init__(self, start_array=None): “”” Initialize new dynamic array DO NOT CHANGE THIS METHOD IN ANY WAY “”” self.size = 0 self.capacity = 4 self.data = StaticArray(self.capacity) # populate dynamic array with initial values (if provided) # before using this feature, implement append() method if start_array is not None: for value in start_array: self.append(value) def __str__(self) -> str: “”” Return content of dynamic array in human-readable form DO NOT CHANGE THIS METHOD IN ANY WAY “”” out = “DYN_ARR Size/Cap: ” out += str(self.size) + “/” + str(self.capacity) + ‘ [‘ out += ‘, ‘.join([str(self.data[_]) for _ in range(self.size)]) return out + ‘]’ def get_at_index(self, index: int) -> object: “”” Return value from given index position Invalid index raises DynamicArrayException DO NOT CHANGE THIS METHOD IN ANY WAY “”” if index < 0 or index >= self.size: raise DynamicArrayException return self.data[index] def set_at_index(self, index: int, value: object) -> None: “”” Store value at given index in the array Invalid index raises DynamicArrayException DO NOT CHANGE THIS METHOD IN ANY WAY “”” if index < 0 or index >= self.size: raise DynamicArrayException self.data[index] = value def __getitem__(self, index) -> object: “”” Same functionality as get_at_index() method above, but called using array[index] syntax DO NOT CHANGE THIS METHOD IN ANY WAY “”” return self.get_at_index(index) def __setitem__(self, index, value) -> None: “”” Same functionality as set_at_index() method above, but called using array[index] syntax DO NOT CHANGE THIS METHOD IN ANY WAY “”” self.set_at_index(index, value) def is_empty(self) -> bool: “”” Return True is array is empty / False otherwise DO NOT CHANGE THIS METHOD IN ANY WAY “”” return self.size == 0 def length(self) -> int: “”” Return number of elements stored in array DO NOT CHANGE THIS METHOD IN ANY WAY “”” return self.size Computer Science Engineering & Technology Python Programming Share QuestionEmailCopy link This question was created from OSU CS261 assignment 2 – v1.04.pdf Comments (0)

Don't use plagiarized sources. Get Your Custom Essay on
count(self, value: object) -> int: This method counts the number of elements in the bag that match the provided ‘value’ object. Example #1: bag = Bag…
Just from $13/Page
Order Essay
  

Leave a Reply

Your email address will not be published.

Related Post

Open chat
💬 Need help?
Hello 👋
Can we help you?