0

When i am typing "rainn", i want to get results for "rain".Here's what i've tried - but there is no success

import mysql.connector
from difflib import get_close_matches

con = mysql.connector.connect(
user = <user>,
password = <password>,
host = <host>,
database = <db>
)

cursor = con.cursor()

word = input('Enter a word: ')

query = cursor.execute('SELECT * FROM Dictionary WHERE Expression = "%s" '% word)
results = cursor.fetchall()


if results:
   for result in results:
       print(results[1])

if len(get_close_matches(word,results))>0:
    print(get_close_matches(word,results))
else:
    print('no word found!')
scottsaenz
  • 90
  • 6
ElMuchacho
  • 300
  • 1
  • 12
  • 1
    One thing worth mentioning: I hope that SQL connection data is all fake for security purposes. That said: We don't need to see the sql code, we need to see what `word` and `results` are at the time you try to get matches, and describe _how_ the result is different from what you want – G. Anderson Jan 23 '20 at 21:33
  • 1
    I'm seeing a match when I manually create a list for results. I would check your results variable. `from difflib import get_close_matches results = ['rain', 'Rain'] word = 'rainn' print(get_close_matches(word,results, cutoff=0.6))` – scottsaenz Jan 23 '20 at 21:36

0 Answers0