#!/usr/bin/env python
prices = [4.0, 3.0, 2.0, 4.0, 3.0, 1.0, 1.1, 1.2, 1.3, 1.4]


class ParserState:
    def __init__(self, window):
        self.best_window = []
        self.current_window = []
        self.skipped = []
        self.window = window

    def increase(self, price):
        if not self.current_window:
            return True
        elif len(self.current_window) == self.window:
            print "Full window"
            print "Skipped:", self.skipped
            return self.current_window[-1] - self.current_window[0] < \
                price - self.current_window[len(self.skipped) + 1]
        else:
            return self.current_window[-1] < price

    def sift(self):
        if not self.best_window or self.best_window[-1] - self.best_window[0] \
           < self.current_window[-1] - self.current_window[0]:
            self.best_window = self.current_window
        self.current_window = []

    def skip(self, price):
        if len(self.skipped) + 1 == self.window:
            # we've moved forward an entire window
            self.sift()
            self.skipped = []
        elif not self.current_window:
            # nothing to do in this case
            return
        else:
            self.skipped.append(price)

    def unskip(self):
        self.current_window.extend(self.skipped)

    def trim(self):
        while len(self.current_window) > self.window:
            self.current_window.pop(0)

    def insert(self, price):
        if self.increase(price):
            print "Price increase:", price
            self.unskip()
            self.current_window.append(price)
            self.trim()
        else:
            self.skip(price)


def main():
    parser = ParserState(3)

    for i, price in enumerate(prices):
        if prices[max(0, i - 1)] < price or price \
           < prices[min(i + 1, len(prices) - 1)]:
            print "Inserting:", price
            parser.insert(price)
        else:
            print "Skipping:", price
            parser.skip(price)

    parser.sift()

    print parser.best_window

if __name__ == "__main__":
    main()

@@ -247,16 +247,127 @@
 window%0A%0A
+    def clear(self):%0A        self.best_window = %5B%5D%0A        self.current_window = %5B%5D%0A        self.skipped = %5B%5D%0A%0A
     def 
@@ -1799,54 +1799,69 @@
 e)%0A%0A
-%0Adef main():%0A    parser = ParserState(3
+    def process(self, prices):%0A        self.clear(
 )%0A%0A    
+  
+  
 for 
@@ -1883,32 +1883,36 @@
 merate(prices):%0A
+    
         if price
@@ -1958,16 +1958,20 @@
         
+ 
+   
 %3C prices
@@ -2001,16 +2001,20 @@
  - 1)%5D:%0A
+    
         
@@ -2055,22 +2055,24 @@
         
-parser
+    self
 .insert(
@@ -2078,38 +2078,46 @@
 (price)%0A        
+   
+ 
 else:%0A
+    
             prin
@@ -2149,22 +2149,24 @@
         
-parser
+    self
 .skip(pr
@@ -2179,40 +2179,151 @@
     
-parser.sift()%0A%0A    print parser.
+    self.sift()%0A        return self.best_window%0A%0A%0Adef main():%0A    parser = ParserState(3)%0A%0A    best_window = parser.process(prices)%0A%0A    print 
 best

Make the process function part of the parser