Lists and Tuples
Douglas Alan
nessus at mit.edu
Fri Dec 5 03:50:35 EST 2003
X-Draft-From: ("comp.lang.python" 285349)
To: bokr at oz.net (Bengt Richter)
Subject: Re: Lists and Tuples
References: <r650tv4f9b2k967jgc0cta3vllfohb49il at 4ax.com>
<7x7k1b4yqn.fsf at ruckus.brouhaha.com>
<eppstein-039667.21452204122003 at news.service.uci.edu>
<bqpfde$426$0 at 216.39.172.122>
Fcc: |rcvstore +articles
From: Douglas Alan <nessus at mit.edu>
--text follows this line--
bokr at oz.net (Bengt Richter) writes:
> On Thu, 04 Dec 2003 21:45:23 -0800, David Eppstein
> <eppstein at ics.uci.edu> wrote:
>> That's true, but another answer is: you should use tuples for short
>> sequences of diverse items (like the arguments to a function). You
>> should use lists for longer sequences of similar items.
> I'm curious what you're getting at. I.e., what does diversity or
> similarity have to do with the choice?
Nothing really, except by idiom. When people use "should" here, I
think they are over-generalizing. Most of the time, records (short
and heterogenious) are used in a read-only fashion, and long
homogenous sequences are used in a read-write fashion. But when
people characterize this tendency with a "should", I think they are
making a thinko. There are times when you need to modify a record and
consequently might use a dictionary or list, rather than a tuple,
and there are also times when you will never want to modify a long,
homogenous sequence, in which case many people would find it more
elegant to use a tuple than to use a list.
The reason for the "should" is probably because, I imagine, Guido had
in mind mostly multiple return values from function, and the like,
when he put tuples into the language.
|>oug
More information about the Python-list
mailing list