tuple versus list

Donn Cave donn at u.washington.edu
Mon Oct 17 12:51:40 EDT 2005


In article <mailman.2141.1129493153.509.python-list at python.org>,
 Bryan <belred at gmail.com> wrote:

> bonono at gmail.com wrote:
> > In this particular case, it seems that (width,height) looks nicer. But
> > I think otherwise, list constuct is easier to read, even though it is
> > supposed to be slower.
> > 
> > With list you can :
> > [a] + [ x for x in something ]
> > 
> > With tuple it looks like this :
> > (a,) + tuple(x for x in something)
> > 
> > I think the list looks cleaner. And since you cannot concat tuple with
> > list, I think unless it looks obvious and natural(as in your case), use
> > list.
> > 
> 
> 
> 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



More information about the Python-list mailing list