2

Python's list structure is like below:

typedef struct {
    PyObject_VAR_HEAD
    PyObject **ob_item;
    Py_ssize_t allocated;
} PyListObject;

Why using **ob_item? I think *ob_item is enough.

1
  • 1
    Are you under the impression that the list's storage physically contains its elements, like a C++ vector or something? The list just holds pointers to its elements. Commented Jan 8, 2017 at 3:44

1 Answer 1

2

Because, as with any list created using pointers, as you add and remove elements, you'll need to change what a node's pointer is pointing to, not just the value of the object being pointed to (which is what you would get with just *ob_item; **ob_item let's you "repoint" the pointer).

Remember, the list is not going to contain the actual objects, it contains pointers to them. To be able to use a pointer that points to a pointer (to, as I mentioned, be able to repoint the pointer for a node), you need **.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.