[英]What is the time complexity of collections.Counter() in Python?
[英]What's the time complexity of Python's collections.Counter.total()?
Python 的 collections.Counter.total() 的時間復雜度是多少? 我已經閱讀了該方法的文檔,但沒有提到它的效率。 有誰知道該方法是如何在后台實現的以及它的時間復雜度是多少?
在 CPython 中,它看起來像是使用sum(self.values())
實現了total()
) ,所以它是O(number of values in the Counter)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.