Question: PYTHON CODING Please write a function called sumDictionaryValues that accepts a single argument: a dictionary variable . The keys of this dictionary will be strings.
PYTHON CODING
Please write a function called sumDictionaryValues that accepts a single argument: a dictionary variable. The keys of this dictionary will be strings. The values of this dictionary will each be a list of numbers. Your function should create a new dictionary. The keys of the new dictionary should be the same as the keys of the original dictionary. The values of the new dictionary should be the sum of the respective values in the the original lists.
Test code (to be executed after your solution):
# Declare the test dictionaries dictA = {"A": [1, 2, 3], "B": [9, -4, 2], "C": [3, 99, 1]} dictB = {"D": [1, 2, 10], "E": [-2, -4, 8], "F": [100000, 0, 1]} dictC = {"G": [-1, -2, 3, 0, 4], "H": [-11, -4, 15], "I": [1]} # Obtain the test results resultA = sumDictionaryValues(dictA) resultB = sumDictionaryValues(dictB) resultC = sumDictionaryValues(dictC) # Check some of the values of resultA print(resultA["A"]) print(resultA["B"]) # Check some of the values of resultB print(resultB["E"]) print(resultB["F"]) # Check some of the values of resultC print(resultC["G"]) print(resultC["I"]) OUTPUT:
6 7 2 100001 4 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
