Question: Our DynamicArray class, as given in Code Fragment 5.3, does not support use of negative indices with _ _getitem_ _. Update that method to better
Our DynamicArray class, as given in Code Fragment 5.3, does not support use of negative indices with _ _getitem_ _. Update that method to better match the semantics of a Python list.
Code Fragment 5.3

1 import ctypes # provides low-level arrays 3 class DynamicArray: "A dynamic array class akin to a simplified Python list." 4 def --init.--(self): "Create an empty array." self._n = 0 6. # count actual elements # default array capacity # low-level array self.capacity = 1 self.A = self.make_array(self._capacity) 9. 10 11 def --len -(self): """ Return number of elements stored in the array." 12 13 return self._n 14 15 def --getitem --(self, k): """' Return element at index k." 16 17 if not 0
Step by Step Solution
3.28 Rating (154 Votes )
There are 3 Steps involved in it
An index such as 3 is equivalent to t... View full answer
Get step-by-step solutions from verified subject matter experts
