Question: template You often have to work with nested data structure. For example, the dictionary on the RHS is a dictionary of list. Your task is
template
You often have to work with nested data structure. For example, the dictionary on the RHS is a dictionary of list. Your task is to sum the numbers in each list. For example sum_numbers(my_dict) returns another dictionary that looks like below { } 5: 15, 2: 3, 3: 2, 4: 0, 1: None If the list is empty, the value should be None, if the list contains non-numerical values, ignore the items. Your dictionary should be sorted by the value in descending order. if dict[key1] and dict[key2] have the same values, sort the entries by key value, for example my_dict = { 1: [1], 2: [2, '2'], 3: ['2',2] } would return { } 2: 4, 3: 4, 1: 1 You often have to work with nested data structure. For example, the dictionary on the RHS is a dictionary of list. Your task is to sum the numbers in each list. For example sum_numbers(my_dict) returns another dictionary that looks like below { } 5: 15, 2: 3, 3: 2, 4: 0, 1: None If the list is empty, the value should be None, if the list contains non-numerical values, ignore the items. Your dictionary should be sorted by the value in descending order. if dict[key1] and dict[key2] have the same values, sort the entries by key value, for example my_dict = { 1: [1], 2: [2, '2'], 3: ['2', 2] } would return { } 2: 4, 3: 4, 1: 1 You often have to work with nested data structure. For example, the dictionary on the RHS is a dictionary of list. Your task is to sum the numbers in each list. For example sum_numbers(my_dict) returns another dictionary that looks like below { } 5: 15, 2: 3, 3: 2, 4: 0, 1: None If the list is empty, the value should be None, if the list contains non-numerical values, ignore the items. Your dictionary should be sorted by the value in descending order. if dict[key1] and dict[key2] have the same values, sort the entries by key value, for example my_dict = { 1: [1], 2: [2, '2'], 3: ['2',2] } would return { } 2: 4, 3: 4, 1: 1
Step by Step Solution
There are 3 Steps involved in it
Iiterating through the dictionary and each list within it summing the numerical values ... View full answer
Get step-by-step solutions from verified subject matter experts
