list vs tuple

Alex Martelli aleaxit at
Fri Mar 30 13:38:20 CEST 2001

"EuphoriaDj" <eddthompson at> wrote in message
news:3ac40acd$0$10576 at
> "Simon Brunning" <SBrunning at> wrote in message
> news:mailman.985789357.19622.python-list at
> > > From: deadmeat [SMTP:root@[]]
> > > Whats the practical difference between a list[] and a tuple() ?
> > >
> > > A tuple seems to be a very basic list, so unless it's faster, what's
> > > point of it?
> >
> > Off the top of my head - A tuple is immutable, and therefore hashable,
> > therefore can be used as a key to a dictionary. I'm sure that there are
> > other things...
> >
> what do you mean by hashable?

Uh, what about "able to be hashed", where "hashed" is the
past participle of verb "to hash"?  Python has a builtin
function "hash", which accepts only "hashable" objects,
and returns an integer:

>>> hash((1,2,3))
>>> hash([1,2,3])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unhashable type

As you see, you can hash a tuple (a tuple is hashable) but
not a list (it's unhashable).  As Simon goes on to say,
being hashable is equivalent to being usable as a key to
a dictionary (since the dictionary internally uses hash
on its keys).


More information about the Python-list mailing list