Hole | Wins | Losses | Score | +17 |
---|---|---|---|---|
1 | 28 | 53 | +17 | (+1) |
10 | ||||
Avg | 28 | 53 | +49 |
Here is the code to parse the given text and extract the relevant information:
import re
# Define a function to extract games from the text
def extract_games(text):
# Use regular expressions to find all game records in the text
patterns = [
r"(\d{1,2}\/\d{1,2}) ([A-Za-z ]+) (\d{3})",
r"(\d{1,2}\/\d{1,2}) ([A-Za-z ]+) vs. ([A-Za-z ]+)"
]
matches = re.findall(patterns, text)
# Create a dictionary to store the game results
games = {}
for match in matches:
date = match[0]
home_team = match[1]
away_team = match[2] if len(match) == 3 else None
score_home = int(match[3]) if len(match) != 4 else None
# Create a new game object with the extracted information
game = {
"date": date,
"home_team": home_team,
"away_team": away_team,
"score": score_home
}
# Add the game to the games dictionary
if home_team in games:
games[home_team].append(game)
else:
games[home_team] = [game]
return games
# Extract the games from the text
games = extract_games(text)
# Print the results
for team, team_games in games.items():
print(f"{team}:")
for game in team_games:
print(f" {game['date']} - {game['home_team']} vs. {game['away_team']} (Score: {game['score']})")
This code uses regular expressions to extract the game records from the text, and then creates a dictionary to store the results. The resulting games dictionary is then printed in a formatted manner.
Please note that this code assumes that the input text follows a specific format, with each game record containing the date, home team, away team (if applicable), and score. If the input text has a different format, you may need to adjust the regular expressions or the code's logic accordingly. Updated: June 26, 2025 at 8:56 PM