简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM