Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27894

Computing win/loss records in Python

From Christopher McComas <mccomas.chris@gmail.com>
Subject Computing win/loss records in Python
Date 2012-08-25 22:20 -0400
Newsgroups comp.lang.python
Message-ID <mailman.3821.1345947609.4697.python-list@python.org> (permalink)

Show all headers | View raw


Greetings,

I have code that I run via Django that grabs the results from various sports from formatted text files. The script iterates over every line in the formatted text files, finds the team in the Postgres database updates their w/l record depending on the outcome on that line, saves the team's row in the db, and then moves on to the next line in the file. 

I'm trying to get away from Django for this project, I want to run the files, get the W/L results and output a formatted text file with the teams and their W/L records. What's confusing me I guess how to store the data/results as the wins and losses tally up. We're talking hundreds of teams, thousands of games, but a quick example would be:

Marshall
Ohio State
Kentucky
Indiana

Marshall,24,Ohio State,48,
Kentucky,14,Indiana,10,
Marshall,10,Indiana,7,
Ohio State,28,Kentucky,10

That's just a quick example, I can handle seperating the data in the lines, figuring it all out, I just am unsure of how to keep a running total of a team's record. I would do "for line in file:" then on the first line I see that Marshall lost so they would have 1, Ohio State won so they'd have 1 win. It'd go to the next line Kentucky 1 win, Indiana 1 loss, then on the 3rd line, Marshall got a win so they'd have 1 win, but it would have to remember that loss from line 1...

Does this make sense?

Thanks,

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Computing win/loss records in Python Christopher McComas <mccomas.chris@gmail.com> - 2012-08-25 22:20 -0400
  Re: Computing win/loss records in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-26 03:38 +0000
  Re: Computing win/loss records in Python Ben Finney <ben+python@benfinney.id.au> - 2012-08-26 14:33 +1000

csiph-web