# An alternative implementation of Stack that
# pushes and pops at _data[0].  Compare the performance
# of this and the original implementation of stack in
# module stack.py.

class Stack:
    """
    A last-in, first-out (LIFO) stack of items
    """

    def __init__(self):
        """ 
        (Stack) -> Nonetype

        Initialize this Stack to be empty.

        >>> s = Stack()
        >>> isinstance(s, Stack)
        True
        """
        
        self._data = []
        
    def pop(self):
        """ 
        (Stack) -> object

        Remove and return the top item from this Stack.

        >>> s = Stack()
        >>> s.push(2)
        >>> s.push(3)
        >>> s.pop()
        3
        """
        
        return self._data.pop(0)
    
    def is_empty(self):
        """ 
        (Stack) -> bool

        Return whether this Stack is empty.

        >>> s = Stack()
        >>> s.push(4)
        >>> s.pop()
        4
        >>> s.is_empty()
        True
        """
        
        return len(self._data) == 0
    
    def push(self, o):
        """ 
        (Stack, object) -> NoneType

        Place object o on top of this Stack.
        """
        
        self._data.insert(0,o)

if __name__  ==  '__main__':
    import doctest
    doctest.testmod()
    
    # uncomment lines below to test performance
    import time
    s = Stack()
    items = range(100000)
    # start the clock
    start = time.time()
    for i in items:
        s.push(i)
    for i in items:
        s.pop()
    end = time.time()
    print ("It took ", end - start, "to push/pop", len(items), "items")