Python Forum
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spell Checker
#1
Hey guys I need help with this program please :)

I need to 
  1. Turn the string into a list of lists, where each sublist has two elements (the mispelling and the correctly spelt word). This is your correctionList
    You can do this by (1) splitting first on the newline character ("\n") and (2) splitting each of those element on the colon (':').
    TESTCASE (1): After the split using '\n' (showing only the first few items):
    ['adress:address', 'alot:a lot', 'athiest:atheist', 'noone:no one' …]


  2.  After the split using :
    [ ['adress', 'address'], ['alot', 'a lot'], ['athiest', 'atheist'], ['noone', 'no one'] … ]


[*]Write a function checkWork(word, correctionList) that can check a word against the list of errors, and if it's incorrect, return the correct spelling.
       The function returns

  • None, if the word wasn't in the list of mispellings OR
  • the correct spelling of the original word


[*]Then write a test framework that lets you input a sentence that may contain errors and displays a corrected version.


So far all I have is this and I am pretty stuck 

def spell_chk():
    checked_list = []
    for item in word_list:
        replacer = SpellingReplacer()
        r = replacer.replace(item)
        checked_list.append(r)
    return checked_list

word_list= [ ['adress', 'address'], ['alot', 'a lot'], ['athiest', 'atheist'], ['noone', 'no one']]
Appreciate any clarification cheers :)
Reply
#2
You're starting at the top. You've got the framework listed in the last bullet point without the pieces listed in the first two parts. Start at the bottom, and write the first two parts.

First you need to convert the string input to a list. From the description, your input is going to look like this:

Output:
adress:address alot:a lot athiest:atheist noone:no one
Convert that text into a list of lists as specified. Point 1 spells out exactly how to do it.

Then write the checkWork (checkWord?) function as described. You are going to want to loop through the list of lists like this:

e = [[2, 7], [1, 8], [2, 8]]
for first, second in e:
    print(first + second)
This is called tuple assignment. The first time through the loop, it will pull the sub-list [2, 7] out of e, and assign that to first, second, sort of like this:

first, second = [2, 7]
Python can handle having two items on the left of the assignment, as long as two items are on the right. It will assign the 2 to first and the 7 to second.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Password Checker Assignment mcostello 1 5,068 Nov-14-2020, 07:54 AM
Last Post: DPaul
  Palindrome checker case sensive edwdas 3 2,634 Nov-07-2019, 05:57 PM
Last Post: nilamo
  "Travis" guest list name checker (Ziyad Yehia Udemy course) Drone4four 8 3,962 Aug-24-2019, 03:46 PM
Last Post: jefsummers
  Syntax checker BZA 4 3,180 May-16-2019, 06:40 PM
Last Post: BZA

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020