[BangPypers] Tuples vs Lists, perfromance difference

Roshan Mathews rmathews at gmail.com
Tue Dec 22 17:22:43 CET 2009


On Tue, Dec 22, 2009 at 7:10 PM, Vishal <vsapre80 at gmail.com> wrote:
> 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.

http://stackoverflow.com/questions/68630/are-tuples-more-efficient-than-lists-in-python

http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/
    Tuples are not constant lists -- this is a common
    misconception. Lists are intended to be homogeneous
    sequences, while tuples are hetereogeneous data
    structures.

Tauber's point about tuples being structures named by index, seemed
correct in light of "namedtuple" in collections (since Python 2.6)

Also, as Noufal mentioned, tuples are hashable, so you can use them as
keys in a dict.

-- 
Roshan Mathews
http://teamtalk.im


More information about the BangPypers mailing list