Computer Science, asked by jspcparrales, 10 months ago

Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. An example file along with the correct output is shown below: example.txt the quick brown fox jumps over the lazy dog Enter the input file name: example.txt brown dog fox jumps lazy over quick the Create and populate your own text file for development.

Answers

Answered by jitendermtr34
4

once upon a time there lived a fox in the jungle one day all of a sudden the fox started searching for food in the jungle but there was no food available so it came back when it came back the fox Savan tree there was hanged so many grapes the fox jumped but it cannot reach to the Grapes so it's thought what do I do with this so grapes and went away

Answered by Agastya0606
1

The python program for the given problem statement is

fname = input("Enter file name: ")

fh = open(fname)

lst = list()                      

words=[];

for line in fh:                    

   words += line.split()

words.sort()

print("The unique words in  alphabetical order are:")

for word in words:

   if word in lst:        

           continue            

   else:                    

           lst.append(word)

           print(word)

#print(lst)

  • The user has to input the text file in the beginning. Then for loop is used in the program with the suitable condition.
  • After that an if-else condition statement is used.
  • Then the output will be displayed on the screen with the first line as - The unique words in alphabetical order are and then the words will be displayed.

#SPJ3

Similar questions