Unable to sort the output based on last occurrence of the scores.
The code aims to identify teams with “cold” scores (in this case, 2-1 and 1-1) based on their recent match history.
the code analyzes team performance based on specific score patterns to identify potential “cold” teams
# Define the sets and their teams' scores
sets = {
"set_A": {
"MAN CITY": ["1-0", "2-1", "1-1", "3-2", "0-0", "1-2", "0-1", "2-0", "1-3", "2-1"],
"IPSWICH TOWN": ["0-2", "1-1", "2-0", "1-0", "0-1", "2-2", "1-3", "1-1", "2-1", "0-0"],
"SOUTHAMPTON": ["2-1", "0-0", "1-2", "3-0", "0-1", "1-1", "2-3", "0-2", "2-0", "1-1"]
},
"set_C": {
"INTER": ["1-0", "0-1", "0-1", "1-2", "3-1", "1-1", "2-2", "2-0", "1-3", "0-2"],
"COMO": ["2-1", "1-1", "0-2", "1-0", "2-1", "1-2", "2-2", "1-1", "1-0", "0-1"]
},
"set_I": {
"BAYERN": ["1-0", "0-1", "2-2", "3-1", "1-1", "0-0", "2-3", "1-2", "2-1", "0-3"],
"FC ST PAULI": ["0-1", "2-2", "0-1", "0-0", "2-0", "1-3", "2-2", "1-0", "3-1", "1-2"]
}
}
cold_scores = ["2-1", "1-1"]
def calculate_coldness(team_scores, cold_scores):
total_matches = len(team_scores)
coldness = 0
last_occurrence = {score: None for score in cold_scores}
for i, score in enumerate(team_scores):
if score in last_occurrence:
last_occurrence[score] = total_matches - i - 1
for score in cold_scores:
score_count = team_scores.count(score)
if score_count == 0:
coldness += 100 # large penalty for not having the cold score
last_occurrence[score] = "never occurred"
else:
coldness += 1 - (score_count / total_matches)
return coldness, last_occurrence
code split due to spam accusuaations
def find_cold_teams(sets, cold_scores):
team_coldness = {}
team_last_occurrences = {}
for set_name, teams in sets.items():
for team, scores in teams.items():
coldness, last_occurrence = calculate_coldness(scores, cold_scores)
team_coldness[team] = coldness
team_last_occurrences[team] = last_occurrence
# Sort teams by coldness in descending order
sorted_teams = sorted(team_coldness.items(), key=lambda item: item[1], reverse=True)
return sorted_teams, team_last_occurrences
Find all teams based on their coldness scores
sorted_teams, team_last_occurrences = find_cold_teams(sets, cold_scores)
Prepare the output lines
output_lines = []
for team, coldness in sorted_teams:
for score in cold_scores:
output_lines.append(f"{team}: {score} {team_last_occurrences[team][score]} Matches ago")
Write the output to a text file
with open('cold_teams.txt', 'w') as file:
for line in output_lines:
file.write(line + 'n')
print("Output written to cold_teams.txt")
What I’m expecting from the script.
FC ST PAULI: 2-1 never occurred Matches ago
FC ST PAULI: 1-1 never occurred Matches ago
INTER: 2-1 never occurred Matches ago
SOUTHAMPTON: 2-1 9 Matches ago
MAN CITY: 1-1 7 Matches ago
BAYERN: 1-1 5 Matches ago
COMO: 2-1 5 Matches ago
INTER: 1-1 4 Matches ago
IPSWICH TOWN: 1-1 2 Matches ago
COMO: 1-1 2 Matches ago
IPSWICH TOWN: 2-1 1 Matches ago
BAYERN: 2-1 1 Matches ago
MAN CITY: 2-1 0 Matches ago
SOUTHAMPTON: 1-1 0 Matches ago