• Home
  • Blog
  • UMCP String Consisting of A Path to A Text File Letter Program

UMCP String Consisting of A Path to A Text File Letter Program

0 comments

I don’t know how to handle this Python question and need guidance.

Write a function called n_letter_words() that takes two arguments:

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”]

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}