Question: Continuing on from the previous question, define a function named create_countries_cases_dict(countries_list) that takes a list of countries as a parameter. The function should read Covid19

Continuing on from the previous question, define a function named create_countries_cases_dict(countries_list) that takes a list of countries as a parameter. The function should read Covid19 data from input text files based on the list of countries given in the parameter list. The function returns a dictionary. The key of the dictionary is the name of the country and the value of the dictionary is a list of monthly total cases for that particular country. The input file name is 'COUNTRY_NAME.txt' where the COUNTRY_NAME is the name of a country from the parameter list. The text file contains 1 or more lines of Covid19 data. Each line consists of the number of cases every day per month. Each data item in a line is separated by whitespace. For example, if the parameter list is:

['NewZealand', 'Finland']

Then, the function should read data from the "NewZealand.txt" text file and read data from the "Finland.txt" text file. Hence, the function should return the following dictionary:

{ 'NewZealand': [99, 121, 93, 177, 32], 'Finland': [8419, 6018, 1815, 654, 214] }

Note: you can assume that the get_lines_from_file() function and get_monthly_cases() function are given.

For example:

Test Result
a_dict = create_countries_cases_dict(['NewZealand', 'Finland']) print(a_dict)
{'NewZealand': [99, 121, 93, 177, 32], 'Finland': [8419, 6018, 1815, 654, 214]} 
a_dict = create_countries_cases_dict(['Australia', 'Taiwan', 'NewZealand']) print(a_dict)
{'Australia': [311, 519, 1393, 9367, 8536], 'Taiwan': [120, 41,

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!