Red Sox Scorecard

Last Updated:
Red Sox logo
HoleWinsLossesScore+1
14437+1(+1)
10
Avg4437+33

Analysis

Here is the code to parse the text and extract the team names:

import re

# Define a dictionary to store team names
teams = {
    'Baltimore Orioles': 0,
    'Boston Red Sox': 0,
    'Chicago White Sox': 0,
    'Cleveland Indians': 0,
    'Detroit Tigers': 0,
    'Kansas City Royals': 0,
    'New York Yankees': 0,
    'Oakland Athletics': 0,
    'Seattle Mariners': 0,
    'Toronto Blue Jays': 0
}

# Define a function to extract team names from the text
def extract_teams(text):
    # Remove any non-alphabetic characters and convert to lowercase
    text = re.sub(r'[^\w\s]', '', text).lower()
    
    # Split the text into lines
    lines = text.split('\n')
    
    # Iterate over each line
    for line in lines:
        # Find all matches of the pattern (team name) followed by a score
        matches = re.findall(r'(\w+)\s*\d+-\d+', line)
        
        # Add 1 to each team's count
        for match in matches:
            teams[match] += 1

# Call the function with the provided text
extract_teams(text)

# Print out the counts of wins and losses for each team
for team, score in sorted(teams.items(), key=lambda x: x[1], reverse=True):
    if score > 0:
        print(f'{team}: {score} - Win')
    else:
        print(f'{team}: {abs(score)} - Loss')

This code uses regular expressions to extract the team names from each line of the text, and then adds up the wins and losses for each team. It also prints out the counts in a sorted format.

Please note that you need to install re module which is Python's built-in module for regular expressions, if not already installed, by running pip install re command. Updated: June 26, 2025 at 8:56 PM