

class StackMin():
    def __init__(self):
        self.stack = []

    def min(self):
        if self.stack == []:
            return None
        else:
            value, info = self.stack[-1]
            return info

    def push(self, value):
        smallest = self.min()
        self.stack.append((value, value if smallest is None else min(value, smallest)))

    def pop(self):
        if self.stack == []:
            return None
        else:
            value, info = self.stack.pop()
            return value

def test():
    stk = StackMin()
    items = [10, 9, 8, 7, 8, 9, 8, 7, 6, 5, 6, 1]
    for item in items:
        stk.push(item)
        print('pushed {}. current min: {}.'.format(item, stk.min()))
    for _ in items:
        item = stk.pop()
        print('popped {}. current min: {}.'.format(item, stk.min()))
    assert stk.pop() is None
        
if __name__ == '__main__':
    test()

@@ -903,8 +903,774 @@
  test()%0A
+%0A%0A#Jessie's solution%0A# 1 -%3E 2 -%3E 3%0A%0Aclass StackMin:%0A    def __init__(self):%0A        self.stack = %5B%5D%0A    def push(self, to_push):%0A        if not self.stack or self.stack%5B-1%5D%5B1%5D %3E to_push:%0A            self.stack.append(%5Bto_push, to_push%5D)%0A        else:%0A            self.stack.append(%5Bto_push, self.stack%5B-1%5D%5B1%5D%5D)%0A    def pop(self):%0A        if self.stack == %5B%5D:%0A            return None%0A        return self.stack.pop()%5B0%5D%0A    def min(self):%0A        if self.stack == %5B%5D:%0A            return None%0A        return self.stack%5B-1%5D%5B1%5D%0A    %0Amy_stack = StackMin()%0Amy_stack.push(5)%0Aprint my_stack.stack, my_stack.min()%0Amy_stack.push(6)%0Aprint my_stack.stack, my_stack.min()%0Amy_stack.push(3)%0Aprint my_stack.stack, my_stack.min()%0Amy_stack.push(7)%0Aprint my_stack.stack, my_stack.min()%0A

Update 2-stack_min.py