tuple versus list
Bryan
belred at gmail.com
Tue Oct 18 00:03:02 EDT 2005
>>
>>i always use the structure analogy. if you view (width, height) as a
>>structure,
>>use a tuple. if you view it a sequence, use a list. in this example, i view
>>it
>>as a stucture, so i would use (width, height) as a tuple.
>
>
> Right, but there's an unfortunate ambiguity in the term "sequence",
> since in Python it is defined to include tuple. I gather you meant
> more in the abstract sense of a data collection whose interesting
> properties are of a sequential nature, as opposed to the way we are
> typically more interested in positional access to a tuple. Maybe
> a more computer literate reader will have a better word for this,
> that doesn't collide with Python terminology. My semi-formal
> operational definition is "a is similar to a[x:y], where
> x is not 0 or y is not -1, and `similar' means `could be a legal
> value in the same context.'"
>
> Donn Cave, donn at u.washington.edu
yes, you are correct. i shouldn't have used the word "sequence" which is a
python term. maybe structure vs. array. in any case, i think the *wrong*
answer that is often given to this question is along the lines of if it's read
only, make it a tuple. if it's read write, make it a list. a great trivial
example is a point. a point is a structure (x, y). if you have many points
then you have a list of structures: [(x, y), (x1, y1), (x2, y2), ...]. to me,
it doesn't matter if you want to modify a point. if you do then create a new
one, but don't make it a list just to make it modifiable.
bryan
More information about the Python-list
mailing list