
'''Implementation of a simple stack data structure.
The stack has push, pop, and peek methods. Items in the stack have a value,
and next_item attribute. The stack has a top attribute.
'''


class Item(object):
    def __init__(self, value, next_item=None):
        self.value = value
        self.next_item = next_item

    def __str__(self):
        return self.value


class Stack(object):
    def __init__(self, top=None):
        self.top = top

    def push(self, value):
        item = Item(value)
        item.next_item = self.top
        self.top = item

    def pop(self):
        pass

    def peek(self):
        return self.top.value


'''Implementation of a simple stack data structure.
The stack has push, pop, and peek methods. Items in the stack have a value,
and next_item attribute. The stack has a top attribute.
'''


class Item(object):
    def __init__(self, value, next_item=None):
        self.value = value
        self.next_item = next_item

    def __str__(self):
        return self.value


class Stack(object):
    def __init__(self, top=None):
        self.top = top

    def push(self, value):
        item = Item(value)
        item.next_item = self.top
        self.top = item

    def pop(self):
        try:
            pop_item = self.top
            self.top = pop_item.next_item
            return pop_item.value
        except AttributeError:
            raise ValueError('No items in stack')

    def peek(self):
        return self.top.value

Add pop method on Stack class
Add pop method on Stack class

  
  '''Implementation of a simple stack data structure.
  The stack has push, pop, and peek methods. Items in the stack have a value,
  and next_item attribute. The stack has a top attribute.
  '''
  
  
  class Item(object):
      def __init__(self, value, next_item=None):
          self.value = value
          self.next_item = next_item
  
      def __str__(self):
          return self.value
  
  
  class Stack(object):
      def __init__(self, top=None):
          self.top = top
  
      def push(self, value):
          item = Item(value)
          item.next_item = self.top
          self.top = item
  
      def pop(self):
-         pass
+         try:
+             pop_item = self.top
+             self.top = pop_item.next_item
+             return pop_item.value
+         except AttributeError:
+             raise ValueError('No items in stack')
  
      def peek(self):
          return self.top.value
  
Add pop method on Stack class
## Code Before:

'''Implementation of a simple stack data structure.
The stack has push, pop, and peek methods. Items in the stack have a value,
and next_item attribute. The stack has a top attribute.
'''


class Item(object):
    def __init__(self, value, next_item=None):
        self.value = value
        self.next_item = next_item

    def __str__(self):
        return self.value


class Stack(object):
    def __init__(self, top=None):
        self.top = top

    def push(self, value):
        item = Item(value)
        item.next_item = self.top
        self.top = item

    def pop(self):
        pass

    def peek(self):
        return self.top.value

## Instruction:
Add pop method on Stack class
## Code After:

'''Implementation of a simple stack data structure.
The stack has push, pop, and peek methods. Items in the stack have a value,
and next_item attribute. The stack has a top attribute.
'''


class Item(object):
    def __init__(self, value, next_item=None):
        self.value = value
        self.next_item = next_item

    def __str__(self):
        return self.value


class Stack(object):
    def __init__(self, top=None):
        self.top = top

    def push(self, value):
        item = Item(value)
        item.next_item = self.top
        self.top = item

    def pop(self):
        try:
            pop_item = self.top
            self.top = pop_item.next_item
            return pop_item.value
        except AttributeError:
            raise ValueError('No items in stack')

    def peek(self):
        return self.top.value
