[Python-il] The Tuples and Lists question
idoa01 at yahoo.com
Wed Jun 11 18:37:24 IDT 2008
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 and x 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.
----- Original Message ----
From: Omer Zak <w1 at zak.co.il>
To: Python User Group <python-il at hamakor.org.il>
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
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.
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
Python-il at hamakor.org.il
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-il