Hole | Wins | Losses | Score | +26 |
---|---|---|---|---|
1 | 32 | 46 | +13 | (+2) |
10 | 32 | 49 | +26 | (+1) |
Avg | 32 | 48 | +44 |
Here is the code in Python to parse and process the baseball game data:
import re
from collections import defaultdict
class Game:
def __init__(self, team1, score1, team2, score2):
self.team1 = team1
self.score1 = int(score1)
self.team2 = team2
self.score2 = int(score2)
def parse_game(game_string):
team1, score1, team2, score2 = re.match(r"(\w+) (\d+)-(\d+)\s+(\w+)\s+(\d+)", game_string).groups()
return Game(team1, score1, team2, score2)
def process_games(games):
team_wins = defaultdict(int)
team_losses = defaultdict(int)
home_runs = defaultdict(int)
for game in games:
if game.score1 > game.score2:
team_wins[game.team1] += 1
team_losses[game.team2] += 1
elif game.score1 < game.score2:
team_wins[game.team2] += 1
team_losses[game.team1] += 1
else:
continue
home_runs[game.team1] += int(game.score1)
home_runs[game.team2] += int(game.score2)
return {
'wins': team_wins,
'losses': team_losses,
'home_runs': home_runs
}
def main():
games = [
# Add each game here, in the format "Team1 Score - Team2 Score"
# For example: "Cubs 3-4 Padres",
"Cubs 8-2 Phillies",
# ... and so on.
]
processed_games = process_games(games)
for team, wins in processed_games['wins'].items():
print(f"{team} won {wins} games")
for team, losses in processed_games['losses'].items():
print(f"{team} lost {losses} games")
for team, home_runs in processed_games['home_runs'].items():
print(f"{team}'s home runs: {home_runs}")
if __name__ == "__main__":
main()
This script defines a Game
class to represent each baseball game, with attributes for the teams and scores. The process_games
function takes a list of games as input and returns three dictionaries: one for wins, losses, and home runs by team.
In the main
function, we can add more games to the games
list and run the script to print out the number of wins, losses, and home runs for each team. Updated: June 26, 2025 at 8:55 PM