implementing stack using python list we use the adapter design pattern to define an arraystack class that uses an underlying python list for storage (we choose the name arraystack to emphasize that the underlying storage is inherently array based one question that remains is what our code should do if user calls pop or top when the stack is empty our adt suggests that an error occursbut we must decide what type of error when pop is called on an empty python listit formally raises an indexerroras lists are index-based sequences that choice does not seem appropriate for stacksince there is no assumption of indices insteadwe can define new exception class that is more appropriate code fragment defines such an empty class as trivial subclass of the python exception class class empty(exception)"""error attempting to access an element from an empty container ""pass code fragment definition for an empty exception class the formal definition for our arraystack class is given in code fragment the constructor establishes the member self data as an initially empty python listfor internal storage the rest of the public stack behaviors are implementedusing the corresponding adaptation that was outlined in table example usage belowwe present an example of the use of our arraystack classmirroring the operations at the beginning of example on page arraystacks push( push( print(len( )print( pop)print( is empty)print( pop)print( is empty) push( push( print( top) push( print(len( )print( pop) push( contentscontents[ contents[ contents[ ]contents[ ]contents[ ]contents]contents]contents[ contents[ contents[ ]contents[ contents[ ]contents[ ]contents[ outputs outputs outputs false outputs outputs true outputs outputs outputs