Lists and Tuples

Donn Cave donn at drizzle.com
Sun Dec 7 22:18:17 EST 2003


Quoth Arthur <ajsiegel at optonline.com>:
| On Fri, 5 Dec 2003 11:10:34 -0600, Skip Montanaro <skip at pobox.com>
| wrote:
|> Generally, choose between tuples and lists based upon your data.  In
|> situations where you have a small, fixed collection of objects of possibly
|> differing types, use a tuple.  In situations where have a collection of
|> objects of uniform type which might grow or shrink, use a list.  For
|> example, an address might best be represented as a tuple:
|>
|>     itcs = ("2020 Ridge Avenue", "Evanston", "IL", "60201")
|>     caffe_lena = ("47 Phila Street", "Saratoga Springs", "NY", "12866")
|>
|> Though all elements are actually strings, they are conceptually different
|> types.  It probably makes no sense to define itcs as

| "Type" is not normally an ambiguous word.  It seems to me that an
| explanation would stress, upfront, that in fact
| homogenous.hetereogenous in this context is at an abstract level, and
| unrelated to type,as such and as your example illustrates. 
|
| Or else, why does the word "type" need to occur at all, other than
| perhaps to explain, explicitily, it is not of relevance

Apologies in advance if someone has already said this.  It may
be a little too algebraic for the Python world, but for me the
difference can be expressed like this -

   n > 0 or m < sizeof(a) and
       conceptual_type(a) == conceptual_type(a[n:m])
   
If that holds, then the conceptual type is naturally implemented
with a list.

I'm not sure it's right to say that the elements of a tuple are
necessarily of conceptually different types, distinguished only
by their positiion.  But the point is that they _are_ distinguished
by position (so a slice is not substitable with its source.)

Of course this still relies on a notion of conceptual type that
can't be expressed literally in Python, but it's a healthy one.

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list