Spell Check

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值