In [10]:
class Node:
    def __init__(self, data, next):
        self.data = data
        self.next = next
        
    def __str__(self):
        return str(self.data)

In [11]:
class Stack:
    def __init__(self):
        self.head = None
        self.length = 0
    
    def push(self, data):
        node = Node(data, self.head)
        self.head = node
        self.length = self.length + 1
    
    def pop(self):
        if not self.isEmpty():
            data = self.head.data
            self.head = self.head.next
            self.length = self.length - 1
            return data
        return None
    
    def isEmpty(self):
        return self.length == 0
    
    def size(self):
        return self.length

In [12]:
stack = Stack()
stack.push("first")
stack.push("second")
stack.push("third")
while not stack.isEmpty():
    print(stack.pop())


third
second
first

In [ ]: