python 3中字典值的总和

Cli*_*ley 1 python dictionary python-3.5

我有以下字典:

dic= {'I-setosa': 8, 'I-versicolor': 2, 'I-virginica': 0}
Run Code Online (Sandbox Code Playgroud)

如何找到密钥的总和?在Python 2我可以做到以下几点:

sum(dic.values())
Run Code Online (Sandbox Code Playgroud)

除此之外,还有其他方法吗?我尝试使用dic.values()并找到该列表的总和,但这太长了。

Ste*_*ann 7

sum(dic.values())
Run Code Online (Sandbox Code Playgroud)

除此之外,还有其他方法吗?

当然。无限多。但是你为什么要问?这是做正确的方式。