pylist concatenate def __add__(self,other)result pylist(size=self numitems+other numitems for in range(self numitems)result append(self items[ ] for in range(other numitems)result append(other items[ ] return result to concatenate two lists we must build new list that contains the contents of both this is an accessor method because it does not mutate either list insteadit builds new list we can do this operation in (ntime where is the sum of the lengths of the two lists here is some code to accomplish this in sect the size is set to the needed size for the result of concatenating the two lists the complexity of the __add__ method is (nwhere is the length of the two lists the initial size of the list does not have to be set because append has ( complexity as we saw in sect howeversince we know the size of the resulting listsetting the initial size should speed up the concatenation operation slightly pylist append this method is hidden since it starts with two underscores it is only available to the class to use def __makeroom(self)increase list size by / to make more room add one in case for some reason self size is newlen (self size / self size newlst [nonenewlen for in range(self numitems)newlst[iself items[ self items newlst self size newlen def append(self,item)if self numitems =self sizeself __makeroom( self items[self numitemsitem self numitems + same as writing self numitems self numitems in sect we learned that the append method has ( amortized complexity when appendingwe will just add one more item to the end of the self items list if there is room in the description of the constructor we decided the pylist objects would contain list that had room for more elements when appending we can make use of that extra space once in while ( after appending some number of items)the internal self items list will fill up at that time we must increase the size of the items list to make room for the new item we are appending by size proportional to the current length of self items this copy belongs to 'acha