tuples vs lists

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Tue Sep 16 19:08:53 CEST 2003


On Tue, 16 Sep 2003 18:51:38 +0200, rumours say that "Ivan Voras"
<ivoras at fer.hr> might have written:

>Are there any performance/size differences between using tuples and using
>lists?

Assuming you know that tuples are immutable and lists are mutable (they
can grow, shrink, get sorted etc), tuples consume less memory (lists
allocate more memory than your list needs, to avoid reallocating space
on every append/insert).  This accounts for size.

Performance-wise, I don't think there is a noticable difference between
indexing lists and tuples (but you can always use the timeit module).

IIRC Guido has stated that tuples are not intended to be immutable
lists, but a kind of handy unnamed structs (a la C) or records (a la
Pascal).

Keep in mind also that lists have useful methods (like count and index)
that tuples don't.  This about functionality.
-- 
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.




More information about the Python-list mailing list