Time complexity for running len(array) in python? -


how python find length of array? stored somewhere in internal data-structure or have iterate through entire thing find length?

i ask because i'm using binary search should run in o(log(n)), doesn't make sense if have iterate through whole thing find length.

lists can store length part of structure. since needs stored in 1 place, can add maximum of o(1) computations , therefore not overhead.

getting length therefore o(1) because it's lookup of field.

for more information, see the docs.