dvlsc000 / EmergingTechnologies

0 stars 0 forks source link

LOAD THE VALID ENGLISH WORDS FROM TEXT #11

Open dvlsc000 opened 2 weeks ago

dvlsc000 commented 2 weeks ago

Load the list of valid English words from words.txt file and return a set of words to match the format of the generated text

dvlsc000 commented 5 days ago

PLAN

  1. Open the file

    • Open the file located at file_path in read mode. The file is expected to contain a list of englishwords, one word per line.
  2. Read and process lines

    • Read all lines and split content into a list of words by line. Each word is automatically stripped of the newline character using splitlines().
  3. Convert to uppercase and store in a set

    • Convert each word to uppercase to ensure consistency with generated text. Store the words in a set to enable fast lookups.
  4. Return the set of words

    • Return the set of words, which can be used to validate if words in the generated text are in this English word list.
dvlsc000 commented 5 days ago

DESIGN DECISIONS

  1. File read and split by lines

    • Ensuring each line is read and split in a single operation, which removes newline characters without needing an additional stripping step.
  2. Conversion to uppercase

    • Converting all words to uppercase to standardize the word format, making it easy to match words with uppercase generated string.
  3. Storing in a set

    • Using a set provides efficient average-time complexity for lookups, making the function optimal.
  4. Flexibility with file path

    • Accepting file_path as a parameter allows the function to load word lists from any file path.