Skip to content

Commit

Permalink
Refactor remove_from_wordlist function to handle
Browse files Browse the repository at this point in the history
multiple inputs
  • Loading branch information
LyubomirT committed Nov 27, 2023
1 parent b9be8f7 commit 9259d16
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lesp/autocorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,25 @@ def extend_wordlist(word):
raise TypeError("Invalid input type. Please provide a string, list, or tuple of alphabetic words.")

def remove_from_wordlist(word):
if word not in wordlist:
raise ValueError(f"\"{word}\" not in wordlist!")
wordlist.remove(word)
if isinstance(word, str):
if word.isalpha():
if word in wordlist:
wordlist.remove(word)
else:
raise ValueError(f"\"{word}\" not in wordlist!")
else:
raise ValueError(f"Invalid input: '{word}' is not a valid word.")
elif isinstance(word, (list, tuple)):
for w in word:
if isinstance(w, str) and w.isalpha():
if w in wordlist:
wordlist.remove(w)
else:
raise ValueError(f"\"{w}\" not in wordlist!")
else:
raise ValueError(f"Invalid input: '{word}' is not a valid word.")
else:
raise TypeError("Invalid input type. Please provide a string, list, or tuple of alphabetic words.")


def stack(source, destination):
Expand Down

0 comments on commit 9259d16

Please sign in to comment.