I don’t know how to handle this Python question and need guidance.
Write a function called n_letter_words() that takes two arguments:
- a string consisting of a path to a text file containing one word per line
- an integer representing a desired word length in characters
Your function should make a list of all words from the file whose length in characters is equal to the value of the second parameter (the desired word length). After reading all words from the file, it should return the list of words of the specified length (be sure to remove leading and trailing whitespace from the line before determining word length). If there were no words of the specified length, your function should return an empty list.
Imagine a file with the following contents:
Apple
Grade
Cherry
Banana
Kiwi
Lemon
Orange
Watermelon
If your function were given a path to this file and a desired word length of 5 characters, it should return the list:
[“apple”, “grape”, “lemon”]


0 comments