简体   繁体   English

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

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

What's the time complexity of Python's collections.Counter.total()? Python 的 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) .在 CPython 中,它看起来像是使用sum(self.values())实现了total() ) ,所以它是O(number of values in the Counter)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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