Learn practical skills, build real-world projects, and advance your career
Created 5 years ago
import jovian
import pandas as pd
#ACTUAL CODE WITHOUT CUSTOM DICTIONARY
%%time
import enchant,difflib
import string
d = enchant.Dict("en_US")
# Taking input from user
sentance = input("Enter word: ")
for c in string.punctuation:
sentance = sentance.replace(c,"")
listofsentances = sentance.split()
actual_message = []
for i in listofsentances:
dict,max = {},0
a = set(d.suggest(i))
for b in a:
tmp = difflib.SequenceMatcher(None, i, b).ratio();
dict[tmp] = b
if tmp > max:
max = tmp
print(dict)
if any(dict.keys()) > 0.2:
actual_message.append(dict[max])
else:
actual_message.append(i)
message = " ".join(actual_message)
Enter word: hello dataa sciecne
{0.8: 'jello', 0.8888888888888888: 'hell', 0.9090909090909091: 'hellos', 1.0: 'hello'}
{0.8888888888888888: 'data', 0.9090909090909091: 'data a', 0.0: 'DAT'}
{0.8571428571428571: 'science'}
CPU times: user 115 ms, sys: 3.17 ms, total: 118 ms
Wall time: 9.03 s
message
'hello data a science'