When should you use a Python list and when should you use array.array or a NumPy array instead?
The earlier questions in this topic looked at lists as a way to hold values, and this one asks when you should pick a different container. The reason a list is slower than a typed array comes down to what each slot of the list actually holds. A list is really a row of pointers, and each pointer refers to a separate object that has its own memory and its own reference count. A typed array stores the raw values directly inside itself, with no separate object for each value and no reference counting at all.
That difference makes array.array the better choice when you have a large number of numbers that are all the same type. The memory saving is roughly four to eight times for 64-bit values. The data sits together in one block, so the processor can read it more quickly. And there is no per-value object overhead at all, which is the part that costs the most when the list is huge.
The catch is that array.array only holds one type. Its type code and its item size are fixed when you create it, so you cannot mix an integer and a string in the same array, and putting in the wrong type raises a TypeError. It also misses the handy methods that a list has. You cannot append an arbitrary type to it, and slicing one gives you back another array instead of a list.
NumPy goes further, and it is what you would normally reach for in numerical work. A NumPy array is not only typed, it is also vectorised. That means one operation applies across the whole array without any Python-level loop, and that is usually a far bigger win than the memory saving. A NumPy array of a million floats takes about eight megabytes, and multiplying it takes only a few milliseconds.
The practical rule to say out loud in an interview is short. Use a list for general-purpose collections that hold mixed objects. Use array.array for a large sequence of simple values of one type where you want to save memory. Use NumPy for anything that involves real numerical computation.