0

I am trying to run a spell check on a list of strings. With the below code i am only getting the error words as (err.word). However i would like to print the string along with error word like

"This is a msspelled string" : msspelled

I have attempted

print("{} ".format(err.word), "{} ".format(chkr.get_text()))

but it's not generating what i want. Any suggestions?

from enchant.checker import SpellChecker
import pypyodbc as db
import pandas as pd

pd.set_option('max_rows', 10000) # overriding default number of rows
pd.set_option('display.max_colwidth', -1)

cnx = db.connect("DNS")
qry = ("""SQL""")
A = pd.read_sql(qry,cnx).to_string()

chkr = SpellChecker("en_US")
chkr.set_text(A)

for err in chkr:
       print("{} ".format(err.word))
pault
  • 41,343
  • 15
  • 107
  • 149
Tayyab Amin
  • 129
  • 1
  • 2
  • 8

1 Answers1

0

Is this what you're trying to do ?

from enchant.checker import SpellChecker
A = "This iis a msspelled string"
chkr = SpellChecker("en_US")
chkr.set_text(A)

# Put all misspelled words in a list
misspelled_words = [err.word for err in chkr]

# Format and print this the sentence with the list of words.
print("{} : {}".format(A, ', '.join(misspelled_words)))
cdrom
  • 591
  • 2
  • 16
  • Not exactly, this code first returns all the text lines and clubs all the misspelled words at the end. I want to print misspelled word parallel to each line – Tayyab Amin May 08 '18 at 10:34