[Tutor] Adding items to dictionaries
Alan Gauld
alan.gauld at freenet.co.uk
Thu Jan 26 15:09:52 CET 2006
> pairs[son][0] = father
> KeyError: 'Steven Bates'
> Where am I going wrong?
A KeyError means you are trying to access an object that does not exist
in the dictionary. And this is true, you haven't added anything for Steven
Bates
yet, but you are trying to access his parents list.
You need to create an associated list which you can then edit.
pairs[son] = [0,0] # need to put dummy data in
pairs[son][0] = father
pairs[son][1] = grandfather
HTH,
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list