PYTHON CODE MODIFICATION ONLY FOR THE FOLLOWING INSTRUCTION. THE STRUCTURE OF THE CODE IS PROVIDES BELOW import
Question:
PYTHON CODE MODIFICATION ONLY FOR THE FOLLOWING INSTRUCTION.
THE STRUCTURE OF THE CODE IS PROVIDES BELOW
import numpy as npfrom Interfaces import List
class ArrayList(List): ''' ArrayList: Implementation of a Listinterface using Arrays. ''' def __init__(self): ''' __init__: Initialize the state (array,n and j). ''' self.n = 0 self.j = 0 self.a = self.new_array(1) def new_array(self, n : int) ->np.array: ''' new_array: Create a new array of sizen Input: n: the size of the newarray Return: An array of size n ''' return np.zeros(n, np.object) def resize(self): ''' resize: Create a new array and copy theold values. ''' pass
def get(self, i : int) -> object: ''' get: returns the element at positioni Inputs: i: Index that is integernon negative and at most n ''' pass
def set(self, i : int, x : object) ->object: ''' set: Set the value x at the indexi. Inputs: i: Index that is integernon negative and at most n x: Object type, i.e., anyobject ''' pass
def append(self, x : object) : self.add(self.n, x) def add(self, i : int, x : object) : ''' add: shift one positionall the items j>=i, insert an element at position i of the listand increment the number of elements in the list Inputs: i: Indexthat is integer non negative and at most n x: Objecttype, i.e., any object ''' pass def remove(self, i : int) -> object: pass
def size(self) -> int: return self.n
def __str__(self): s = "[" for i in range(0, self.n): s += "%r" % self.a[(i +self.j) % len(self.a)] if i
def __getitem__(self, i) -> object: ''' __getitem__: Returns theitem in the position i in array format, i.e., l[i] where l is a listinstance Input: i: positiveinteger less than n Return: the item at indexi ''' if isinstance(i, slice): return [self.get(i) for iin range(i.start, i.stop)] else: return self.get(i)
def __iter__(self): self.iterator = 0 return self
def __next__(self): if self.iterator < self.n: x = self.a[(self.iterator+ self.j) % len(self.a)] self.iterator +=1 else: raiseStopIteration() return x
'''arraylist = ArrayList()arraylist.append("a")arraylist.append("b")arraylist.append("c")arraylist.append("d")arraylist.append("e")arraylist.append("f")arraylist.append("g")arraylist.append("h")
'''
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill