Tuple question

Peter Hansen peter at engcorp.com
Thu Sep 2 23:35:54 EDT 2004


Aahz wrote:

> In article <P5GdnUwq-8QI6KrcRVn-qg at powergate.ca>,
> Peter Hansen  <peter at engcorp.com> wrote:
> 
>>Why do you think tuples use significantly less memory than lists?
>>As far as I know, they don't.  (They do use less, but if you are
>>really talking about huge amounts of data such that you would
>>be trying to optimize in this way, then the amount that they use
>>is not *significantly* less.)
> 
> Actually, if you have large numbers of short sequences, the memory
> savings from tuples can indeed be significant.  I don't remember off-hand
> what the number is, but I think it's something on the order of 20%.

Differing definitions of "significant", I guess, because
nothing less than about a 2:1 ratio would make me consider
optimizing to use tuples instead of lists...

Consider, for example, that one actually has to build the
tuple in the first place... how can you do that without
having the info in a list to begin with?  (I'm sure there
are ways if one is ingenious, but I think the answers
would just go to prove the point I was making.)

-Peter



More information about the Python-list mailing list