As James Tauber once put it in a blog post:
"the index in a tuple has an implied semantic. The point of a tuple is
that the i-th slot means something specific. In other words, it's a
index-based (rather than name based) datastructure."
( http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/ 
)

It is also mentioned in the same blog post (quoting Phillip Eby) that "Lists 
are intended to be homogeneous sequences, while tuples are hetereogeneous data 
structures.". 
so you tend to assume that if x is a list then x[0] and x[1] are of the same 
base class, while you don't make that assumption on tuples. 
This is a semantic non-enforced distinction, but it still is a distinction.

Ido.


----- Original Message ----
From: Omer Zak <[EMAIL PROTECTED]>
To: Python User Group <[email protected]>
Sent: Wednesday, June 11, 2008 3:28:01 PM
Subject: [Python-il] The Tuples and Lists question

I have a silly question:
Why does Python have both Tuples and Lists?

The only programmer-visible difference, of which I am aware, between
them is that Tuples are immutable and Lists are mutable, with the
following implications:
1. Tuples can be used as hash (Dict) keys, and Lists cannot.
2. When you modify a Tuple, a new Tuple is created.  On the other hand,
List modification happens in place.

I don't see why is the above difference good enough reason to have
different notations for Tuples and Lists.
                                           --- Omer
-- 
Every good master plan involves building a time machine.  Moshe Zadka
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



      
_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

לענות