'TypeError: list indices must be integers, not str' Python 3 -


i need bit of assignment (first time posting on se please excuse lack of posting etiquette if any)

so code had write spell checker. supposed is:

1.) check through 2 lists (one dictionary, correctly spelled words, other user input list should have incorrectly spelled word or two)

2.) suggest correct word in place of misspelled word (example if spelled heloo, spell checker spelled wrong , suggest word hello, help, etc.)

my biggest problem right @ line 19, getting list indices must integers problem.

any appreciated, , finishing appreciated! feel outside of syntax more improved upon. thanks.

here code, not finished

import re  def words_from_file(filename): try:     f = open(filename, "r")     words = re.split(r"[,.;:?\s]+", f.read())     f.close()     return [word word in words if word] except ioerror:     print("error opening %s reading. quitting" % (filename))     exit()   user_word = words_from_file('user_word.txt') suggestion = words_from_file('big_word_list.txt') sug_list = []  in user_word:     if user_word[a] not in suggestion:         print ("spelling error: %s"%(user_word[a]))         in suggestion:             j in suggestion[i]:                 if len(suggestion[i][j]) == len(user_word[a]-2):                     count = 0                     similarities = len(user_word[a])                     k in suggestion[i][j]:                         if suggestion[i][j][k] in suggestion:                             count+=1                             if count >= similarities:                                 sug_list.append(suggestion[i][j]) 

change:

for in user_word:     if user_word[a] not in suggestion: 

into:

for in user_word:     if not in suggestion: 

because items in user_word list iterated using a variable. a in each iteration contain nonempty string obtained line split. can use numerical index list type. you've used string in place of numeric index causes error message.


Popular posts from this blog