赞
踩
Test = {'a': 2, 'b': 10, 'c': 5}
print(max(Test.values()))
>> 10
Test = {'a': 2, 'b': 10, 'c': 5}
print(min(Test.values()))
>> 2
import numpy as np
Test = {'a': 2, 'b': 10, 'c': 5}
average = np.mean(test.values())
运行后报错: TypeError: unsupported operand type(s) for /: ‘dict_values’ and ‘int’
错误原因: dict.values()
return a object, not a list or tuple
解决方法:
import numpy as np
Test = {'a': 2, 'b': 10, 'c': 5}
average = np.mean(list(test.values()))
>>5.666666666666667
Test = {'a': 2, 'b': 10, 'c': 5}
print(sum(Test.values()))
>> 17
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。