Python的collections.Counter.total()的时间复杂度是多少?

Fou*_*ree 0 python python-collections

Python的collections.Counter.total()的时间复杂度是多少?我已阅读该方法的文档,但没有提及其效率。有谁知道该方法是如何在幕后实现的以及它的时间复杂度是多少?

rch*_*ome 5

在 CPython 中,看起来它是total()使用 using实现的sum(self.values()),所以它是O(number of values in the Counter).