0

I have a dict and want to search in it.

test = dict({u'K\xfcndigung' : 123})
tmpKey = str('K\xfcndigung')
print(test[tmpKey])

It results in:

UnicodeWarning: Unicode equal comparison failed to convert both 
arguments to Unicode - interpreting them as being unequal
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

It seems you are using Python2, :

>>> test[tmpKey]

Warning (from warnings module):
  File "__main__", line 1
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    test[tmpKey]
KeyError: 'K\xfcndigung'

Well in Python2, str are not unicode as opposed in Python3, thus make tmpKey as a unicode object instead:

>>> tmpKey = u'K\xfcndigung'
>>> #        ^
>>> 
>>> test[tmpKey]
123
Iron Fist
  • 10,739
  • 2
  • 18
  • 34