Computer Science
How are lists internally stored ? How are 2D lists internally stored ?
Linear Lists
1 Like
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
What are ragged lists ? How are these different from two dimensional lists ?
Suggest a situation where you can use ragged list ?
Create a list SqLst that stores the doubles of elements of another list NumLst. Following code is trying to achieve this. Will this code work as desired ? What will be stored in SqLst after following code ?
NumLst = [2, 5, 1, 7, 3, 6, 8, 9] SqLst = NumLst * 2
Change the above code so that it works as stated in previous question.