Question: Define a function named print_table(name, column_names, a_dict) which takes a table name, a list of column names and a dictionary of data as parameters and
Define a function named print_table(name, column_names, a_dict) which takes a table name, a list of column names and a dictionary of data as parameters and prints the table as shown in the examples below. For example, if the table name is 'Regions', the column names list is ['Auckland region', 'Northland region'] and the dictionary is:
{'Northland region': [(2021, 2262), (2022, 2367)], 'Auckland region': [(2021, 20520), (2022, 20469)]} then the function prints the table below:
produces:
Regions |2021 |2022 | -------------------------------- Auckland region |20520 |20469 | Northland region |2262 |2367 |
Note:
You can assume that all parameters are valid.
The width of the first column (i.e. label) in the table is obtained by calling the get_longest_string_length() function that you wrote in Q6. You can assume that the function is given.
The width of the remaining columns in the table is obtained by calling the get_longest_column_length() function that you wrote in Q7. You can assume that the function is given.
You may find the f-string helpful. For example: use "{name:<{width}}" to print the name with a specific width value.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
