When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead?

John Machin sjmachin at lexicon.net
Fri Apr 20 18:37:36 EDT 2007


On Apr 21, 7:09 am, Luis M. González <luis... at gmail.com> wrote:
> On Apr 20, 3:28 pm, Bjoern Schliessmann <usenet-
>
> mail-0306.20.chr0n... at spamgourmet.com> wrote:
> > Luis M. González wrote:
> > > I don't remember exactly where I read about it, but Guido said
> > > once that tuples are being kept mainly for historical reasons.
>
> > Weren't tuples added when lists already existed?
>
> > Regards,
>
> > Björn
>
> > --
> > BOFH excuse #101:
>
> > Collapsed Backbone
>
> I tried googling for these comments, but I couldn't find them.
> Perhaps I never read them and it was just my imagination...
> Anyway, I suggest reading this chapter of "Dive into Python" for a
> good explanation of the differences between tuples and lists:http://diveintopython.org/native_data_types/tuples.html
>
> The article explains that, amongst other things, tuples are faster
> than lists, so if you are working with constant values (inmutables)
> they are more indicated than lists.
>

One inessential but very useful thing about tuples when you have a lot
of them is that they are allocated the minimum possible amount of
memory. OTOH lists are created with some slack so that appending etc
can avoid taking quadratic time.




More information about the Python-list mailing list