Short version of my question: Why is it common practice in Python to initialize an empty list even when the size of the list might change many times such as the following:
arr = []
for i in range(10):
arr.append(i)
Isn't it computationally expensive to change the size of an array iteratively?
Long version of my question: I'm used to using MATLAB and am relatively new to Python. When I want to create an array, it is common practice in MATLAB to initialize an array of zeros of appropriate size, and then replace the elements of the array with the elements you want to end up with. This is because changing the size of an array iteratively in MATLAB is computationally expensive. Is there something about Python that avoids this expense? When I see people answer Python questions on this website that involve preinitializing a list to be added to, they always create an empty list and subsequently change the size, something I have always regarded as inefficient.