Question
Define the get_names_num_tuple_dict() function which is passed a filename as a parameter. The file contains lines of text where each line is made up of
Define the get_names_num_tuple_dict() function which is passed a filename as a parameter. The file contains lines of text where each line is made up of a name followed by a series of numbers. An example input file is shown below ("ShortNamesAndNums.txt"):
The get_names_num_tuple_dict() function returns a dictionary with the names as the keys and the corresponding values which are tuples of numbers. The first number after the name controls how many numbers are in the corresponding tuple (the numbers included in the tuple are taken from the left to right). For example, the line of text "Ali 6 7 6 5 12 31 61 9" has 6 as the first number after the name and this line of text becomes the dictionary entry with the keyword "Ali" and the corresponding value is a tuple made up of the next six integers "Ali": (7, 6, 5, 12, 31, 61). You can assume that there are always enough numbers in each line of the input file.
Note: the testing code makes use of the print_dict_in_key_order(a_dict) which prints the dictionary pairs in sorted key order.
For example, the following code:
names_and_nums_dict = get_names_num_tuple_dict("ShortNamesAndNums.txt")
print_dict_in_key_order(names_and_nums_dict)
Expected:
Ali - (7, 6, 5, 12, 31, 61) Bella - (2, 6, 2, 2, 30) Elmo - (3, 8, 6, 8) Gill - (9, 7) Jin - (26, 51, 3)ShortNamesAndNums.txt Edited Bella 5 2 6 2 2 30 4 8 9 2 Gill 2 9 7 54 67 Jin 3 26 51 3 344 23 Elmo 4 3 8 6 8 Ali 6 7 6 5 12 31 61 9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started