arrays listing continued def __init__selfthearray )self _arrayref thearray self _curndx def __iter__self )return self def __next__self )if self _curndx lenself _arrayref entry self _arrayrefself _curndx self _curndx + return entry else raise stopiteration the constructoras shown in lines - handles the creation and initialization of the array using the technique described earlier it also defines two data fields needed for the implementation of the array adtone to store reference to the array structure and another to store the number of elements allocated for the array the latter is needed since hardware-supported arrays do not keep track of this value the initialization of the array is done by calling the clear(method the clear(method is used to set each element of the array to given valuewhich it does by iterating over the elements using an index variable the len methodwhich returns the number of elements in the arraysimply returns the value of size that was saved in the constructor the iter method creates and returns an instance of the arrayiterator private iterator classwhich is provided in lines - of listing the definition of the array adt calls for the implementation of the subscript operatorwhich allows for the use of array objects in manner similar to other python collection types in pythonas in most languagesthe subscript notation can be used to read the contents of an array element or to modify an element thusthere are two different methods that must be definedas shown in lines - firstthe getitem operator method takes the array index as an argument and returns the value of the corresponding element the precondition must first be verified to ensure the subscript is within the valid range when the subscript notation is used in programy [ ]python will call the getitem methodpassing the value of to the index parameter since python expects the getitem method to return valueit is your responsibility to make sure this occurs the setitem operator method is used to set or change the contents of specific element of the array it takes two argumentsthe array index of the element being modified and the new value that will be stored in that element before the element is modifiedthe precondition must be tested to verify the subscript is within the valid range python automatically calls the setitem method when the subscript notation is used to assign value to specific elementx[iy the indexispecified in the subscript is passed as the first argument and the value to be assigned is passed as the second argument__setitem__( ,