Respuesta :
Answer:
unique = []
with open("file_name.txt", "r") as file:
lines = file.readlines()
for line in lines:
# assuming comma is the only delimiter in the file
words = line.split()
for word in words:
word = word.strip()
if word not in unique:
unique.append(word)
unique = sorted(unique)
print(unique)
Explanation:
The python module opens a file using the 'with' keyword (the file closes automatically at the end end of the indentation) and the open built-in function and reads the content of the open file as a list of lines of the content.
Each line is split into a list and the unique words are collected and stored in the unique list variable.
The program is an illustration of file manipulations.
File manipulation involves writing to and reading from a file
The program in Python where comments are used to explain each line is as follows:
#This creates an empty list
wordList = []
#This opens the file
with open("myFile.txt", "r") as file:
#This reads the file, line by line
lines = file.readlines()
#This iterates through each line
for line in lines:
#This splits each line into words
words = line.split()
#This iterates through each word
for word in words:
#This removes the spaces in each word
word = word.strip()
#This adds unique words to the list
if word not in wordList:
wordList.append(word)
#This prints the unique words in alphabetical order
print(sorted(wordList))
Read more about similar programs at:
https://brainly.com/question/19652376