list vs tuple

Courageous jkraska1 at san.rr.com
Fri Mar 30 01:53:19 EST 2001


>> Off the top of my head - A tuple is immutable, and therefore hashable, and
>> therefore can be used as a key to a dictionary. I'm sure that there are
>> other things...

>what do you mean by hashable?

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> h={}
>>> mylist=[1,2,3]
>>> mytuple=(1,2,3)
>>> h[mylist]=3
Traceback (innermost last):
  File "<pyshell#3>", line 1, in ?
    h[mylist]=3
TypeError: unhashable type
>>> h[mytuple]=3
>>> h[mytuple]
3
>>> 




More information about the Python-list mailing list