[Tutor] dictionary datatype

Alan Gauld alan.gauld at freenet.co.uk
Wed Apr 12 19:01:15 CEST 2006


> For example, I have a dictionary:
> dict1 = { 0x2018:u'k', 0x2019:u'd'}
> 
> I assign:
> n = 0x2018
> print dict1[n]
> 
> Then:
> KeyError: '0x2018'

The error is complaining that you are using a string as a key.
Are you sure you aren't assigning

n = '0x2018'

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