""" Module for an alternative Stack implementation
"""
from container import Container
from container import EmptyContainerException


class Stack2(Container):
    """
    Last-in, first-out (LIFO) stack.
    """

    def __init__(self):
        """ Create a new, empty Stack self.

        Overrides Container.__init__

        @param Stack self: this stack
        @rtype: None
        """
        self._contents = []

    def add(self, obj):
        """
        Add object obj to top of Stack self.

        @param Stack self: this Stack
        @param object obj: object to place on Stack
        @rtype: None
        """
        # we insert at the front of the list of items
        self._contents.insert(0, obj)

    def remove(self):
        """
        Remove and return top element of Stack self.

        Assume Stack self is not empty.

        @param Stack self: this Stack
        @rtype: object

        >>> s = Stack()
        >>> s.add(5)
        >>> s.add(7)
        >>> s.remove()
        7
        """
        if self.is_empty():
            raise EmptyContainerException
        # we remove and return the element at the front of the list of items
        return self._contents.pop(0)

    def is_empty(self):
        """ Return whether Stack self is empty.

        @param Stack self: this Stack
        @rtype: bool
        """
        return len(self._contents) == 0
