Q. A dictionary D1 has values in the form of lists of numbers. Write a program to create a new dictionary D2 having same keys as D1 but values as the sum of the list elements.
e.g.
D1 = {'A': [1, 2, 3], 'B': [4, 5, 6]}
Then
D2 is {'A':6, 'B': 15}
Answer =
dic1 = eval(input("Enter dictionary :-")) dic2 = {} for i in dic1 : lst = dic1[ i ] sum_of_num = sum( lst ) dic2 [ i ] = sum_of_num print(dic2)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )