increment = 0 decrement = 0 same = 0 increment_3 = 0 decrement_3 = 0 same_3 = 0 with open('input', 'r') as fp: last=[] for i,line in enumerate(fp): amt = int(line) if(i > 0): if(amt > last[-1]): increment = increment + 1 elif(amt < last[-1]): decrement = decrement + 1 else: same = same + 1 if(i > 2): if(amt > last[-3]): increment_3 = increment_3 + 1 elif(amt < last[-3]): decrement_3 = decrement_3 + 1 else: same_3 = same_3 + 1 last.append(amt) if(i > 2): last.pop(0) # oldest is gone! print "Increased:", increment print "Decreased:", decrement print " Remained:", same print "Increased_3:", increment_3 print "Decreased_3:", decrement_3 print " Remained_3:", same_3