Utf-8 String As Key In Dictionary Causes Keyerror
I have a dictionary with unicode strings as keys. When I try to access the value I get key error, even though the printout of the key in dictionary and my key are equal: >>&g
Solution 1:
Your test
is a string while key
is a unicode string. See the u
in-front of it?
You should either use Python 3, where all strings are unicode strings, or make sure to convert test to unicode before looking for it in the dictionary.
Post a Comment for "Utf-8 String As Key In Dictionary Causes Keyerror"