removing elements from list python' list class offers several ways to remove an element from list call to popremoves the last element from list this is most efficientbecause all other elements remain in their original location this is effectively an ( operationbut the bound is amortized because python will occasionally shrink the underlying dynamic array to conserve memory the parameterized versionpop( )removes the element that is at index of listshifting all subsequent elements leftward to fill the gap that results from the removal the efficiency of this operation is ( )as the amount of shifting depends upon the choice of index kas illustrated in figure note well that this implies that pop( is the most expensive callusing (ntime (see experiments in exercise - - figure removing an element at index of dynamic array the list class offers another methodnamed removethat allows the caller to specify the value that should be removed (not the index at which it residesformallyit removes only the first occurrence of such value from listor raises valueerror if no such value is found an implementation of such behavior is given in code fragment again using our dynamicarray class for illustration interestinglythere is no "efficientcase for removeevery call requires (ntime one part of the process searches from the beginning until finding the value at index kwhile the rest iterates from to the end in order to shift elements leftward this linear behavior can be observed experimentally (see exercise - def remove(selfvalue)"""remove first occurrence of value (or raise valueerror""notewe do not consider shrinking the dynamic array in this version for in range(self )found matchif self [ =valueshift others to fill gap for in range(kself )self [jself [ + self [self none help garbage collection we have one less item self - return exit immediately only reached if no match raise valueerrorvalue not found code fragment implementation of remove for our dynamicarray class