我从另一个函数中得到了像这样的元组:('falseName', 'realName', positionOfMistake)
,例如 ('Milter', 'Miller', 4)
。
我需要编写一个函数来创建这样的字典:
D={realName:{falseName:[positionOfMistake], falseName:[positionOfMistake]...},
realName:{falseName:[positionOfMistake]...}...}
函数必须将字典和上述元组作为参数进行传递。我最初的想法是这样的:
def addToNameDictionary(d, tup):
dictionary={}
tup=previousFunction(string)
for element in tup:
if not dictionary.has_key(element[1]):
dictionary.append(element[1])
elif:
if ...
但是它不起作用,而且我有点卡在这里了。