Python implements list with references in memory (i.e., pointers if you might say) to its actual elements. These references are contiguous in memory. Example:
# RefX, RefY and RefZ are contiguous memory references to the following elements
list_example = [elementX, elementY, elementZ]
#insert elementS at (index 1) will shift all the next references (RefY and RefZ in this
case) in the memory (assume each ref is 8 bit size)
list_example = [elementX, elementS, elementY, elementZ]
#Therefore insert operation time complexity is O(N)
My question is:
In case of 2D list: If I append an element to the end of the first list:
list_of_lists[0].append(item)
would this case result in shifting the references of elements in second and third list in memory?
My main point: I am asking because I am wondering if implementing list of three stacks (as a list of lists) is costly operation in terms of time complexity in case of append or pop?