Python word counter program

Am getting the error below when the program execute:

Traceback (most recent call last):
  File "C:/Users/User/Downloads/Py/file.py", line 41, in <module>
    sentences_list = get_sentences(file_name)
  File "C:/Users/User/Downloads/Py/file.py", line 13, in get_sentences
    sentences_list.remove('')
ValueError: list.remove(x): x not in list

The program is supposed to count the number of sentences, words, and unique words. As you input or after

reading “speech.txt”, count the sentences (they end with periods) then

count the words. To distinguish words, you may want to remove all punctuation

and control characters: for example commas, periods, and newLines(i.e. ‘n’).

Then to limit unique words, convert all letters to lower case, split the text

into a list of words, and sort the list alphabetically to assist counting. Speech.txt can have any random number of words

Example output is

           Speech Analysis:
            Sentences = 11
            Words = 260
            Unique words = 142

Here is the Python code snipper

        sentences_list = message.split('.')
        sentences_list.remove('')
    
        

Answer

list.remove(x) will raise value error if x is not found in list. What you can do is – print the list before removing (”) from the list to see if it’s in the list or not.

Another thing that you should do is error/exception handling

try:
    sentences_list.remove('')
except ValueError as e:
    print("('') not in sentence list")
    pass # or do something else here