Caculate age

Laura Creighton lac at strakt.com
Mon Feb 3 09:10:54 EST 2003


Ai!  I went and looked at the archives at http://mail.python.org/pipermail/python-list/2003-February

and I cannot find my article.  No wonder you want my head.  It is probably
sitting at home in my lap top, happily waiting for mh to confirm that I
want to send it or something.  But that doesn't make it any better.

Here is what happened.

It was tired.  I started a reply that used a list, as I was thinking about
what would Ben want if people input the same dates into his problem.  Then
I decided that this was a bad idea.  In the meantime I had written 
'lists of numbers make bad keys for dictionaries'. I changed things 
removing the lists.  I really botched the comment.

Ben: numbers make fine keys:

>>> mydict={}
>>> for i in range(5):
...     mydict[i] = i
...
>>> print mydict.keys()
[4, 3, 2, 1, 0]
>>> print mydict.values()
[4, 3, 2, 1, 0]

but lists do not:

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

Of course, you weren't trying to do that anyway.

I most humbly and abjectly apologise for all the confusion I have caused.

Laura Creighton





More information about the Python-list mailing list