implementing stack in python now that we have clearly defined the stack as an abstract data type we will turn our attention to using python to implement the stack recall that when we give an abstract data type physical implementation we refer to the implementation as data structure as we described in in pythonas in any object-oriented programming languagethe implementation of choice for an abstract data type such as stack is the creation of new class the stack operations are implemented as methods furtherto implement stackwhich is collection of elementsit makes sense to utilize the power and simplicity of the primitive collections provided by python we will use list recall that the list class in python provides an ordered collection mechanism and set of methods for exampleif we have the list [ ]we need only to decide which end of the list will be considered the top of the stack and which will be the base once that decision is madethe operations can be implemented using the list methods such as append and pop the following stack implementation assumes that the end of the list will hold the top element of the stack as the stack grows (as push operations occur)new items will be added on the end of the list pop operations will manipulate that same end completed implementation of stack adt class stackdef __init__(self)self items [def is_empty(self)return self items =[def push(selfitem)self items append(itemdef pop(self)return self items pop(def peek(self)return self items[len(self items)- def size(self)return len(self itemsremember that nothing happens when we click the run button other than the definition of the class we must create stack object and then use it shows the stack class in action as we perform the sequence of operations from table stack(print( is_empty() push( push('dog' the stack abstract data type