Computer Science

How are lists internally stored ? How are 2D lists internally stored ?

Linear Lists

3 Likes

Answer

Lists in Python are stored similarly to strings in memory. However, lists store references to their elements at each index, which can vary in size. This means that each index of a list holds a reference to the actual object stored elsewhere in memory. Each of the individual items in the list occupies its own memory location.

When it comes to 2D lists, also known as lists of lists, they follow a similar principle. Internally, a 2D list is represented as an array of pointers to inner lists. Each element of the outer list is a reference to an inner list object, which in turn is another array of pointers to the elements it contains.

Answered By

1 Like


Related Questions