gpt4 book ai didi

python - python 3中字典值的总和

转载 作者:太空宇宙 更新时间:2023-11-04 07:36:00 25 4
gpt4 key购买 nike

我有以下字典:

dic= {'I-setosa': 8, 'I-versicolor': 2, 'I-virginica': 0}

如何找到键的总和?在 Python 2 中,我可以执行以下操作:

sum(dic.values())

除了这个还有别的办法吗?我尝试使用 dic.values() 并找到该列表的总和,但它太长了。

最佳答案

sum(dic.values())

Is there any other way than this?

当然。无穷多。但你为什么要问?这是正确的做法。

关于python - python 3中字典值的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35447057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com