比较 python 中相应索引处的键和值

compare key and values at corresponding index in python

python.key中有字典,值拼写为compared.if错误大于等于2,打印不正确

输入={"their":"thuyr"}

输出=不正确(因为 t=t,h=h 但 e!=u,i!=y)。

我的问题是我无法比较 t==t,h==h,e==u,i==y。 下面的代码显示计数值 22 但计数值必须为 2 因为只有两个单词与他们的

不匹配
def find_correct(words_dict):
    count=0
    for key,value in words_dict.items():
        for val in value:
            for ky in key:
                if(val!=ky):
                    count+=1  
    return count     

print(find_correct({"their":"thuor"})) 

这是因为您使用了嵌套循环。它将 "their" 中 "t" 的每个字母与 "thuor" 中的每个 5 个字母进行比较。相反,只需使用这样的单个循环:

def find_correct(words_dict):
count=0
for key,value in words_dict.items():
    for val, ky in zip(value, key):
        if(val!=ky):
            count+=1  
return count