What is the cost of len() function for Python built-ins? (list/tuple/string/dictionary)
len()
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.
set
array.array
2.1m questions
2.1m answers
60 comments
57.0k users