The Python module array supports arrays, which are, unlike lists, stored in a contiguous manner, giving performance characteristics which are often more desirable. But the types of elements are limited to those listed in the documentation.
I can see why the types have to be ones with constant (or at least bounded from above) representation size. But don't pointers fall into that category? (The main implementation is written in C which, admittedly, allows pointers to different types to have different sizes, but they're all (perhaps except pointers to C functions, but that's not an issue for this question) convertible to intptr_t
.) So, given boxing, arrays of arbitrary Python objects could be easily implemented, right? So why aren't they?
because we have lists, which are exactly an array of pointers.
python's array
module stores data contiguously, python objects have dynamic sizes and cannot be stored contiguously, so we have lists which store the pointers.
the main use of array
is for passing around C-style arrays between different C functions, arrays are slower than lists for numeric types due to the boxing and unboxing, so it has no use in any pure python code.