Source

data_munging_code_kata / soccer / goals_spread.py

import re
import math


class GoalSpread():
	
	def __init__(self):
		self.team = None
		self.min_diff = None
		
	def load_file(self):
		print 
		return open('./data/football.dat','r')
		
	def eval_spread(self):
		file = self.load_file()
		
		for line in file:
			row = line.split()
			
			if len(row) > 0 and re.search("^[0-9]*\.$",row[0]):
				
				team = row[1]
				spread = math.fabs(int(row[6]) - int(row[8]))
				
				if not self.min_diff or self.min_diff > spread:
					self.min_diff = spread
					self.team = team
		
		return self.team