len() 函数的成本 [英] Cost of len() function
本文介绍了len() 函数的成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
len()
<的成本是多少/a> Python 内置函数?(列表/元组/字符串/字典)
What is the cost of len()
function for Python built-ins? (list/tuple/string/dictionary)
推荐答案
对于您的每种类型都是 O(1)(恒定时间,不取决于元素的实际长度 - 非常快)已经提到了,加上set
和其他的比如array.array
.
It's O(1) (constant time, not depending of actual length of the element - very fast) on every type you've mentioned, plus set
and others such as array.array
.
这篇关于len() 函数的成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文