+ 1

Calculate the sum of dict values in magic_dict by taking only into account numerical values

magic_dict= dict(val1=44,val2='secret value',val3=55.0,val4=1) Sum_of_values = assert sum_of_values= =100

24th Dec 2019, 4:42 PM
SRINATH CHOWDARY
SRINATH CHOWDARY - avatar
3 Réponses
24th Dec 2019, 5:16 PM
r1c5
r1c5 - avatar
+ 1
or even sumOfValues = sum(x for x in magic_dict.values() if type(x)!=str)
24th Dec 2019, 6:00 PM
Bilbo Baggins
Bilbo Baggins - avatar
0
sum_list = [] for x in magic_dict.values(): if type(x)!=str: sum_list.append(x) print(sum(sum_list))
15th Dec 2022, 9:30 PM
Rohit Gaikwad
Rohit Gaikwad - avatar