1#!/usr/bin/python 2import re, sys 3 4def parse_file(filename): 5 data = {} 6 for line in open(filename): 7 if re.match('\d', line): 8 (samples, percent, symbol) = line.split() 9 data[symbol] = float(percent) 10 return data 11 12 13data1 = parse_file(sys.argv[1]) 14data2 = parse_file(sys.argv[2]) 15 16delta = {} 17for symbol in data1.keys() + data2.keys(): 18 delta[symbol] = data1.get(symbol, 0) - data2.get(symbol, 0) 19 20def lookup_delta(symbol): 21 return delta[symbol] 22 23sorted_deltas = sorted(delta.keys(), key=lookup_delta, reverse=True) 24 25if len(sorted_deltas) > 40: 26 sorted_deltas = sorted_deltas[0:20] + sorted_deltas[-20:] 27 28for symbol in sorted_deltas: 29 print '%2.3f %s' % (delta[symbol], symbol) 30