tuple question

Warren Postma embed at NOSPAM.geocities.com
Wed Jun 14 16:23:24 EDT 2000


I first came across the term tuple in relation to Relational Algebra and in
particular, in the realm of SQL and Databases.

A row of data in a database is often called a tuple. Really, it's a way of
creating a Structure like you would do in C, very efficiently, which once
created, is immutable. This means you can create a hash on it, and then use
the hash to get the piece of data out of a database table.   This is exactly
how Tuples work, and they are hashed and then placed into an associative
array (Python calls associative arrays Dictionaries).

So whereas there is one native Array type in C, the List type in Python is a
mutable dynamically sized array, and a Tuple is a fixed immutable grouping
of items, and a Dictionary is like an array where the key doesn't have to be
a number.  So, three kinds of things which have something in common with a C
array is better than just having a return to the Bad Old Days where C arrays
were fixed in size, mutable to the point that you could easily crash your
system, and totally non-polymorphic.

Warren





More information about the Python-list mailing list