How Does Len(array) Work Under The Hood
So take an array: x = [1,2,3,4] How does python get the length of this array when you call len(x) At first glance an obvious solution seems to be that it iterates through the
Solution 1:
The Python docs are pretty clear here (my highlighting):
Python's lists are really variable-length arrays, not Lisp-style linked lists. The implementation uses a contiguous array of references to other objects, and keeps a pointer to this array and the array's length in a list head structure.
Note that Python 3's FAQ has the identical text.
Post a Comment for "How Does Len(array) Work Under The Hood"