Size of tuples

Jeff Shannon jeff at ccvcorp.com
Fri Sep 7 15:18:50 EDT 2001


Peter van der Kamp wrote:

> Hello,
>
> Thanks to the answers I understand that big tuples
> aren't really a problem. I realise that it would have
> been easy to test it myself, but sharing experiences
> isn't that bad. To answer some of the
> questions asked to me: the memory of my machine
> is 64 Mb. The reason I need a big tuple is: I'm trying
> to develop a text retrieval program in Python. Tuples
> seem to be convenient to store the references to the
> individual words of a text.
> Thanks again for the answers!

You might be better off using dictionaries.  Then you can index by the
word itself.  And if the value changes for whatever reason, you only
have to modify that particular value, instead of creating an entire new
tuple.

indexes = {}
for word in text.split():
    indexes[word] = find_index(word)

def retrieve_index(word):
    return indexes[word]

Of course, you'll probably want to add checks for multiple occurences of
words as you're building your dictionary (you could possibly use a tuple
of indexes as your value, in that case).  There's lots that can be done
with dictionaries--I've found them to be useful in a huge variety of
situations.

Jeff Shannon
Technician/Programmer
Credit International






More information about the Python-list mailing list