当前位置: 首页 > 工具软件 > Spell Check > 使用案例 >

Spell Check

屠锐
2023-12-01

http://programarcadegames.com/index.php?chapter=lab_spell_check

Requirements

Write a single program in Python that checks the spelling of the first chapter of “Alice In Wonderland.” First use a linear search, then use a binary search. Print the line number along with the word that does not exist in the dictionary.

Follow the steps below carefully. If you don't know how to accomplish one step, ask before moving on to the next step.

import re

def split_line(line):
    return re.findall('[A-Za-z]+(?:\'[A-Za-z]+)?',line)

file=open("dictionary.txt")

dictionary_list = []
for line in file:
    line = line.strip()
    dictionary_list.append(line)
    
print( "There were",len(dictionary_list),"names in the file.")
file.close()

print("---Liner Search---")

file = open("AliceInWonderLand200.txt")

words = []
for line in file:
    word_line = split_line(line)
    for l in word_line:
        word = split_line(l)
        words.append(word)        
print(words)

for i in words:
    for j in dictionary_list:
        if words[i] == str(dictonary_list[j]):
            break
    print("Line",i,"possible misspelled word:",words[i])
        
        

还是错的。。。

报错:

Traceback (most recent call last):
  File "E:\python\text\text.py", line 30, in <module>
    if words[i] == str(dictonary_list[j]):
TypeError: list indices must be integers, not list



 类似资料:

相关阅读

相关文章

相关问答