Arrays Vs. Lists

Alex Martelli aleaxit at yahoo.com
Tue Feb 18 06:20:57 EST 2003


Tetsuo wrote:

> What exactly is the significant difference?  How is each defined, and
> how are arrays oh so fast, and when are lists better?

Assuming you're talking about Python iself...:

lists are Python built-ins and can have items of any type -- in
particular they can be heterogeneous, i.e. have items of many
different types in the same list -- maximum flexibility.

arrays are obtained by importing module array from the standard
Python library and must be homogeneous -- have items all of the
same type (each a number, or character).  This lets you save some
memory, because the type is only recorded once and then each
item takes up only a few bytes.  Unless your program's pushing
your real-memory availability, though, saving memory won't change
your program's speed in dramatic ways.


The distinctions are different in other languages.  For Python,
too, you can get a popilar extensionu package called "Numeric",
which defines arrays that are rather different from those of
the standard library module named 'array'.


Alex





More information about the Python-list mailing list