lists and tuples
John Hunter
jdhunter at ace.bsd.uchicago.edu
Thu Jun 26 10:16:03 EDT 2003
>>>>> "Gerrit" == Gerrit Holl <gerrit at nl.linux.org> writes:
Gerrit> I don't understand. I really don't understand.
For me, the most important distinction is that because lists are
mutable, they cannot be used as keys in a dictionary. Because tuples
are immutable, they can.
d = {}
l = [1,2]
t = (1,2)
d[l] = 'Nope' # TypeError: list objects are unhashable
d[t] = OK'
I find myself using tuples very often as keys for dictionaries.
John Hunter
More information about the Python-list
mailing list