Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Spell Check
  • Loading branch information
JayvynClarke committed Nov 26, 2023
commit 4db50548730a1d4257748464dd719767d55515ca
61 changes: 29 additions & 32 deletions Lab 10 - Spell Check/lab_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def main():
break;

if not found:
print("possible misspelling: ", word, " at line ", line_number)
# if uppercase_word in dictionary_list:
# print("{word}")
# else:
# print("Not found in dictionary")
print("Line", line_number, "possible misspelled word:", word)

line_number += 1

Expand All @@ -47,33 +43,34 @@ def main():
print("---Binary Search---")
my_file = open("AliceInWonderLand200.txt")
line_number = 1
start = 0
end = len(dictionary_list) - 1
found = False

while start <= end and not found:
middle = (end + start) // 2

if dictionary_list[middle] < word:
end = middle + 1
elif dictionary_list[middle] > word:
start = middle - 1
else:
found = True

if not found:
print("possible misspelling: ", word, "at line", line_number)
my_file.close()

main()
for line in my_file:
line = line.strip()
word_list = split_line(line)

for word in word_list:
found = False
word_upper = word.upper()
start = 0
end = len(dictionary_list) - 1

while start <= end and not found:
middle = (end + start) // 2
key = dictionary_list[middle]

if key < word_upper:
start = middle + 1
elif key > word_upper:
end = middle - 1
else:
found = True
break

if not found:
print("Line", line_number, "possible misspelled word:", word)

# while start <= end:
# mid = (start + end) // 2
# mid_word = dictionary_list[mid]
line_number += 1

my_file.close()

# if mid_word == word:
# found = True
# elif mid_word < word:
# start = mid + 1
# else:
# end = mid - 1
main()