Oct-04-2020, 01:18 AM
Hello everyone. I am having trouble understanding how to store a set in a dictionary's value.
I have to read a file that contains a chronological list of the world series winning teams from 1903 to 2009, where the first line in the file is the name of the team that won in 1903 and the last line in the file is the name of the team that own in 2009.
I have a function called get_dict that will take the team_list (a list of the teams that won) and build a dictionary, so keys ware individual team names found in the file, and each values is a set that contains the year in the file where the team won.
So, I read the file and store the team names in a list, then create a dictionary with it. I created the function before I realized I had to use sets in the dictionary's value. But I don't know how to use the sets. Can you look at my function and tell me where I can go from here?
I have to read a file that contains a chronological list of the world series winning teams from 1903 to 2009, where the first line in the file is the name of the team that won in 1903 and the last line in the file is the name of the team that own in 2009.
I have a function called get_dict that will take the team_list (a list of the teams that won) and build a dictionary, so keys ware individual team names found in the file, and each values is a set that contains the year in the file where the team won.
So, I read the file and store the team names in a list, then create a dictionary with it. I created the function before I realized I had to use sets in the dictionary's value. But I don't know how to use the sets. Can you look at my function and tell me where I can go from here?
def get_dict(team_list): winning_dict = {} value = 1903 for index in team_list: winning_dict[index] = value value += 1 return winning_dict