Home > Blockchain >  What's the time complexity of Python's collections.Counter.total()?
What's the time complexity of Python's collections.Counter.total()?

Time:12-03

What's the time complexity of Python's collections.Counter.total()? I've read the documentation for the method, but there's not mention of its efficiency. Does anyone know how the method is implemented under the hood and what its time complexity is?

CodePudding user response:

In CPython, it looks like it implements total() using sum(self.values()), so it's O(number of values in the Counter).

  • Related