subject
Computers and Technology, 27.03.2021 02:10 vicor

This program reads a file called 'test. txt'. You are required to write two functions that build a wordlist out of all of the words found in the file and print all of the unique words found in the file. Remove punctuations using 'string. punctuation' and 'strip()' before adding words to the wordlist. Write a function build_wordlist() that takes a 'file pointer' as an argument and reads the contents, builds the wordlist after removing punctuations, and then returns the wordlist. Another function find_unique() will take this wordlist as a parameter and return another wordlist comprising of all unique words found in the wordlist.
Example:
Contents of 'test. txt':
test file
another line in the test file
Output:
['another', 'file', 'in', 'line', 'test', 'the']
This the skeleton for 1:
#build_wordlist() function goes here
#find_unique() function goes here
def main():
infile = open("test. txt", 'r')
word_list = build_wordlist(infile)
new_wordlist = find_unique(word_list)
new_wordlist. sort()
print(new_wordlist)
main()

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 15:20
What does a bonus object do? a. subtracts lives b. keeps track of a player's health c. gives a player an advantage d. makes text appear
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
The more powerful, 60 volt cables and the main power shut off on an hev are both colored orange
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Jean has kept the content of her website limited to what is important; she has also ensured that the text follows a particular style and color all throughout her website. which website features has jean kept in mind? jean has limited the content of her website to what is important; this ensures (clarity, simplicity, harmony and unity) of the content. she has also formatted the text in a particular style and color throughout her website, ensuring (balance, simplicity, consistency)
Answers: 2
question
Computers and Technology, 24.06.2019 10:10
Which view in a presentation program displays a split window showing the slide in the upper half and a blank space in the lower half?
Answers: 1
You know the right answer?
This program reads a file called 'test. txt'. You are required to write two functions that build a w...
Questions
question
Mathematics, 15.12.2020 21:10
question
Spanish, 15.12.2020 21:10
question
Mathematics, 15.12.2020 21:10
question
Biology, 15.12.2020 21:10
question
Biology, 15.12.2020 21:10
question
Mathematics, 15.12.2020 21:10
question
Mathematics, 15.12.2020 21:10
question
Mathematics, 15.12.2020 21:10