Oct-05-2020, 10:42 PM
(This post was last modified: Oct-05-2020, 11:05 PM by SalsaBeanDip.)
Ok so I updated my code again and it seems to work so far
Ok so I guess I do still have some problems with my code. When I try to display the winning years for a team, it is not correct. In fact, each team's winning years I try to display are exactly the same. However, there could be a problem with my code to display the team's winning years. In main I ask the user to enter a team's name and then I display the team's winning years:
Also, the years are out of order for some reason?
def get_dict(team_list): winning_dict = {} value = 1903 for index in team_list: winning_dict[index] = set() if index in winning_dict: winning_dict[index].add(value) elif index not in winning_dict: winning_dict[index] = set(value) value += 1 return winning_dictDoes this look ok to you?
Ok so I guess I do still have some problems with my code. When I try to display the winning years for a team, it is not correct. In fact, each team's winning years I try to display are exactly the same. However, there could be a problem with my code to display the team's winning years. In main I ask the user to enter a team's name and then I display the team's winning years:
#a call to the get_dict function winning_dict = {} winning_file = open('WorldSeriesWinners.txt', 'r') team_list = winning_file.readlines() winning_file.close() for index in range(len(team_list)): team_list[index] = team_list[index].rstrip('\n') winning_dict = get_dict(team_list) #now to display a team's winning years key = input("Enter a team's name: ") for key in winning_dict: result = winning_dict.get(key, 'Team not found') print(result, end=' ')But it doesn't matter which team I enter because they all display the same thing:
Output:{1903} {1994} {1954} {2005} {1908} {1979} {1930} {2007} {1914} {1990} {1948} {2000} {1924} {2006} {1984} {1955} {1957} {1988} {1983} {1986} {1989} {2008} {1985} {1991} {1993} {1995} {2003} {2001} {2002}
First of all, the curly brackes are not supposed to be displayed and these are NOT the correct winning years.Also, the years are out of order for some reason?