Re:Functional programming in Python
by pjscott on Saturday May 12, 2012 @12:35AM
(#3962768)
A tuple, behind the scenes, is just a type tag, a refcount, a length, and an array of PyObject pointers. A list, instead of having a fixed array of PyObject pointers, has a pointer to a dynamically resizable array of them. Tuples and lists are both iterable, they both have O(1) indexing and fairly efficient internal representations, but the key difference is mutability. A tuple is supposed to be a composite data type; a list is a dynamic array that you store things in.
Aside from mutability, though, tuples can do pretty much anything lists can, and usually a bit more efficiently.
Aside from mutability, though, tuples can do pretty much anything lists can, and usually a bit more efficiently.