s are yellow limes are green then the list ["red", "yellow", "green"] s

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

The function last_words in python takes one parameter, fname, the name of a text file, and returns a list containing the last word from each line of the file. For example, if the file contents are:

apples are red bananas are yellow limes are green

then the list ["red", "yellow", "green"] should be returned.

NOTE: You may assume the file will contain no blank lines.

BIG HINT: If line is a string representing a line of text (inside a for loop!), then L = line.split() creates a list of the words in the line.

For example:

Test Result
L = last_words("wordlist1.txt") print(L) ['happy', 'sad', 'angsty', 'euphoric', 'maudlin']
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT