Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何根据len-1或len+匹配字典中的单词;1.python_Python_List_Comparison - Fatal编程技术网

如何根据len-1或len+匹配字典中的单词;1.python

如何根据len-1或len+匹配字典中的单词;1.python,python,list,comparison,Python,List,Comparison,如果我有一个单词“raqd”,我将如何使用python进行拼写检查,也就是说,在“拼写检查”中找到单词“rad”作为选项?我一直想做的是: def isbettermatch(keysplit, searchword): i = 0 trues = 0 falses = 0 lensearchwords = len(searchword) keysplits = copy.deepcopy(keysplit) searchwords = cop

如果我有一个单词“raqd”,我将如何使用python进行拼写检查,也就是说,在“拼写检查”中找到单词“rad”作为选项?我一直想做的是:

def isbettermatch(keysplit, searchword):
    i = 0
    trues = 0
    falses = 0

    lensearchwords = len(searchword)

    keysplits = copy.deepcopy(keysplit)
    searchwords = copy.deepcopy(searchword)
    #print keysplit, searchwords
    if len(keysplits)  == len(searchwords)-1:
        i = 0
        while i < len(keysplits):
            j = 0
            while j < lensearchwords:
                if keysplits[i] == searchwords[j]:
                    trues +=1
                    searchwords.pop(j)
                    lensearchwords = len(searchwords)
                elif keysplits[i] != searchwords[j]:
                    falses +=1
                j +=1
            i +=1
        if trues >= len(searchwords)-1:
            #print "-------------------------------------------------------", keysplits
            return True            

这只是我得到的单词的一个小例子,

很久以前,我曾为一项课程作业写过一次拼写检查。它必须像你说的那样:给一个“单词”,给一个字母添加或删除,建议所有可能的匹配项。我记得我所做的是将主词典单词列表加载到一个哈希表中(具有快速O(1)访问功能),然后针对给定的单词,生成所有可能的字母添加和删除组合,并检查它们是否在主单词列表中。任何匹配项都将用作建议

对于更复杂的拼写检查器,您可以尝试使用Levenshtein距离编写BK树:

请查看:@SnakesandCoffee,我希望它更多地基于我迄今为止编写的代码。我以前在研究我的问题时确实看到过这个例子,但我想我必须毁掉我写的所有东西。你的方法的基础是什么?你的问题是什么?没有理由你不能阅读诺维格文章中的理论并自己实现它,而不复制他的代码。一个人如何使用哈希表?对不起,我是一个学生beginner@pearbear:在Python中,字典相当于哈希表。以这种方式使用Python dict现在是使用集合完成的。防止创建所有值为0或无的假“映射”,只是为了快速检查密钥空间中是否存在。set()中的值是在当前Python版本(大约从v2.4开始)中如何实现的。
dna   ira   fra   had   har   nra   jar   jaq   bra   era   amd