Question: def get_game_dict(game_data: TextIO) -> Dict[str, List[int]]: Return a dictionary containing the team name and a list of points earned in each game for each team

def get_game_dict(game_data: TextIO) -> Dict[str, List[int]]: """Return a dictionary containing the team name and a list of points earned in each game for each team in the open file game_data. >>> input_file = open('sample_games.txt') >>> get_game_dict(input_file) {'Toronto Maple Leafs': [2, 2, 1, 0, 0, 2], 'Grande Prairie Storm': [], \ 'Montreal Canadiens': [1, 2, 1, 0, 2]} >>> input_file.close() """

answer = {} prename = '' for data in game_data: line = data.strip() if line.isnumeric(): answer[prename].append(int(line)) else: prename = line answer[prename] = [] return answer

Sample_games.txt

Toronto Maple Leafs 2 2 Grande Prairie Storm Toronto Maple Leafs 1 0 0 2 Montreal Canadiens 1 2 1 0 2

When I run this code, I get

>>> input_file = open('sample_games.txt') >>> get_game_dict(input_file) {'Toronto Maple Leafs': [1, 0, 0, 2], 'Grande Prairie Storm': [], \ 'Montreal Canadiens': [1, 2, 1, 0, 2]} >>> input_file.close()

But I want to get >>> input_file = open('sample_games.txt') >>> get_game_dict(input_file) {'Toronto Maple Leafs': [2, 2, 1, 0, 0, 2], 'Grande Prairie Storm': [], \ 'Montreal Canadiens': [1, 2, 1, 0, 2]} >>> input_file.close()

**please look at the bold part

How can I fix this?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!