user30869
user30869

Reputation: 19

Python Spell Checker Linear Search

I'm learning Python and one of the labs requires me to import a list of words to serve as a dictionary, then compare that list of words to some text that is also imported. This isn't for a class, I'm just learning this on my own, or I'd ask the teacher. I've been hung up on how to covert that imported text to uppercase before making the comparision.

Here is the URL to the lab: http://programarcadegames.com/index.php?chapter=lab_spell_check

I've looked at the posts/answers below and some youtube videos and I still can't figure out how to do this. Any help would be appreciated.

Convert a Python list with strings all to lowercase or uppercase

How to convert upper case letters to lower case

Here is the code I have so far:

# Chapter 16 Lab 11

import re

# This function takes in a line of text and returns
# a list of words in the line.
def split_line(line):
    return re.findall('[A-Za-z]+(?:\'[A-Za-z]+)?',line)

dfile = open("dictionary.txt")

dictfile = []
for line in dfile:
    line = line.strip()
    dictfile.append(line)

dfile.close()

print ("--- Linear Search ---")

afile = open("AliceInWonderLand200.txt")

for line in afile:
    words = []
    line = split_line(line)
    words.append(line)
    for word in words:   
        lineNumber = 0
        lineNumber += 1
        if word != (dictfile):
            print ("Line ",(lineNumber)," possible misspelled word: ",(word))

afile.close()

Upvotes: 1

Views: 875

Answers (1)

Lennart Regebro
Lennart Regebro

Reputation: 172319

Like the lb says: You use .upper():

dictfile = []
for line in dfile:
    line = line.strip()
    dictfile.append(line.upper()) # <- here.

Upvotes: 1

Related Questions