Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function, get_words_from_file(filename) , that returns a list of lower case words as specified in the introduction.Your function should only process lines between the

Write a function, get_words_from_file(filename), that returns a list of lower case words as specified in the introduction.Your function should only process lines between the start and end marker lines and use the definition of words provided by the professor. The words should be in the same order as they occur in the file.

Feel free to write helper functions as you see fit but remember these will need to be included in your answer to this question and subsequent questions.

We have used books that were encoded in UTF-8 and this means you will need to use the optional encoding parameter when opening files for reading. That is your open file call should look like open(filename, encoding='utf-8'). This will be especially helpful if your operating system doesn't set Python's default encoding to UTF-8.

For example:

Test Result
filename = "abc.txt" words2 = get_words_from_file(filename) print(filename, "loaded ok.") print("{} valid words found.".format(len(words2))) print("Valid word list:") print(" ".join(words2))
abc.txt loaded ok. 3 valid words found. Valid word list: a ba bac
# NOTE: Don't use synthetic.txt from SQ3 # - this is a new file filename = "synthetic.txt" words = get_words_from_file(filename) print(filename, "loaded ok.") print("{} valid words found.".format(len(words))) print("Valid word list:") for word in words: print(word) 
synthetic.txt loaded ok. 73 valid words found. Valid word list: toby's code was rather interesting it had the following issues short meaningless identifiers such as n and n deep complicatednesting a doc-string drought very long rambling and unfocused functions not enough spacing between functions inconsistent spacing before and after operators just like this here boy was he going to get a low style mark let's hope he asks his friend bob to help him bring his code up to an acceptable level

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions