Help understanding the decisions *behind* python?
masklinn at masklinn.net
Fri Jul 31 15:31:21 EDT 2009
On 31 Jul 2009, at 20:48 , Emmanuel Surleau wrote:
> On Friday 31 July 2009 19:49:04 Raymond Hettinger wrote:
>> On Jul 20, 9:27 am, Phillip B Oldham <phillip.old... at gmail.com>
>>> Specifically the "differences" between lists and tuples have us
>>> confused and have caused many "discussions" in the office. We
>>> understand that lists are mutable and tuples are not, but we're a
>>> little lost as to why the two were kept separate from the start.
>>> both perform a very similar job as far as we can tell.
>> The underlying C code for the two is substantially the same. In
>> of code, tuples are in effect just immutable lists that have the
>> feature of being hashable (and therefore usable as dictionary keys or
>> elements of sets).
>> Beyond the mutable/hashable distinction, there is an important
>> philosophical distinction articulated by Guido. He deems tuples
>> to be useful for struct like groupings of non-homogenous fields
>> and lists to be useful for sequences of homogenous data suitable
>> for looping.
>> While nothing in the list/tuple code requires you to make that
>> it is important because that philosophy pervades the language. If
>> follow Guido's direction, you'll find that the various parts of the
>> language fit together better. Do otherwise and you'll be going
>> the grain.
> I might be wrong, but I get the impression that many people don't
> indeed "get
> it" and use tuples as static arrays and lists when the array needs
> to be
> dynamically resized. This is certainly how I use them as well.
> This would tend to show that Guido's notion here was not particularly
It's intuitive if you come to Python knowing other languages with
tuples (which are mostly functional, and in which tuples are *never*
sequences/iterables). At the end of the day, and if Guido's intention
truly was what Raymond says, implementing tuples as immutable sequence
was a mistake. And the documentation is to blame as well: in it,
tuples are clearly described as a *sequence* type, not a *structure*
More information about the Python-list