每个键都与值进行比较(可以说键和值之间有拼写检查)。如果只有两个单词不匹配,则打印该键
input={“their”:“thuor”,“diksha”,“dijmno”} 输出=[“他们的”]
def find_correct(words_dict):
count=0
final_list=[]
for key,value in words_dict.items():
for i in range(len(value)): # this may need adjusting for different length words
if(value[i]!=key[i]):
count+=1
if(count<=2):
final_list.append(key)
return final_list
print(find_correct({"their":"thuor","diksha":"dijmno"}))
这可以通过列表理解和集合来完成
相关问题 更多 >
编程相关推荐