[BangPypers] Tuples vs Lists, perfromance difference

Noufal Ibrahim noufal at gmail.com
Tue Dec 22 16:42:52 CET 2009

On Tue, Dec 22, 2009 at 7:10 PM, Vishal <vsapre80 at gmail.com> wrote:

> Hi,
> I was presuming that since tuples are immutable, like strings, and string
> immutability increases performance (
> http://effbot.org/pyfaq/why-are-python-strings-immutable.htm)
> so also, using tuple would improve performance over Lists.
> is this presumption correct?

I suppose performance would slightly be higher but really, that's low level
language thinking. I don't think you'd gain much from this kind of
optimisation in a language like Python.

> if it is, then as a practice, If I know the contents of my sequence at the
> time of initialization and the fact that the sequence is not going to
> change
> at runtime, would it be always good to use tuples instead of lists.
> Any views on this one?

Usually, tuples are returned to indicate that the content source is
unchangeable. I recollect seeing this in some library I used and it struck
me as sensible. Also, if you want a hashable list (eg. for a dictionary

There are reasons to use them but performance (YMMV) is not one of them.


More information about the BangPypers mailing list