Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Exercise 4: Download a copy of the file from www.py4e.com/code3/romeo.txt Write a program to open the file romeo.txt and read it line by line. For each line, split the line into a list of words using...

1 answer below »
Exercise 4: Download a copy of the file from www.py4e.com/code3/romeo.txt Write a program to open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split function. For each word, check to see if the word is already in a list. If the word is not in the list, add it to the list. When the program completes, sort and print the resulting words in alphabetical order. Enter file: romeo.txt ['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
Please attach a word doc with the program before and after it runs similar to the attached.
Answered 3 days After Apr 19, 2021

Solution

Neha answered on Apr 22 2021
155 Votes
81214 - python code/code.py
#to store each word of the file
lst = []
#take file name as input from use
filename = input("Please enter file name: ")
#open file to read
with open(filename,'r') as file:
# read each line from the file
for line in file:
# read each word from the line
for word in line.split():
#add each word in the list
lst.append(word)

#list to store words with single existence
es = []
#each...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here