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

460 Views Asked by At

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?

1

There are 1 best solutions below

0
rchome On BEST ANSWER

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