+ 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
3 Respostas
+ 1
or even
sumOfValues = sum(x for x in magic_dict.values() if type(x)!=str)
0
sum_list = []
for x in magic_dict.values():
if type(x)!=str:
sum_list.append(x)
print(sum(sum_list))