I have such a code:
corpus_file = codecs.open("corpus_en-tr.txt", encoding="utf-8").readlines()
corpus = []
for a in range(0, len(corpus_file), 2):
corpus.append({'src': corpus_file[a].rstrip(), 'tgt': corpus_file[a+1].rstrip()})
params = {}
for sentencePair in corpus:
for tgtWord in sentencePair['tgt']:
for srcWord in sentencePair['src']:
params[srcWord][tgtWord] = 1.0
Basically I am trying to create a dictionary of dictionary of float. But I get the following error:
Traceback (most recent call last):
File "initial_guess.py", line 15, in <module>
params[srcWord][tgtWord] = 1.0
KeyError: u'A'
UTF-8 string as key in dictionary causes KeyError
I checked the case above, but it doesn't help.
Basically I don't understand why unicoded string 'A' is not allowed in python to be a key value? Is there any way to fix it?