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, 22.06.2019 11:30
What does a cascading style sheet resolve a conflict over rules for an element? a. the rule affecting the most content wins b. the rule affecting the most content loses c. the rule with the most specific selector loses d. the rule with the most specific selector wins
Answers: 2
question
Computers and Technology, 23.06.2019 03:30
Ihave a singular monitor that is a tv for my computer. recently, i took apart my computer and put it back together. when i put in the hdmi cord and booted the computer to see if it worked, the computer turned on fine but the screen was blue with "hdmi no signal." i've tried everything that doesn't require buying spare parts, any answer is appreciated!
Answers: 1
question
Computers and Technology, 23.06.2019 04:31
Which of the following is not a way in which trees benefit the environment? a. they remove a significant amount of carbon dioxide from the atmosphere. b. they remove a significant amount of oxygen from the atmosphere. c. their roots hold soil in place, reducing rates of erosion. d. they remove ozone and particulates from the atmosphere. select the best answer from the choices provided a b c d
Answers: 1
question
Computers and Technology, 25.06.2019 06:10
In your pest busters game, how does player 2 move the ship_2 object? a pressing the w and s keys b. pressing the up arrow and down arrow keys c. moving the mouse from side to side d. moving the mouse up and down select the best answer from the choices provided
Answers: 3
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
English, 30.11.2020 20:10
question
Mathematics, 30.11.2020 20:10
Questions on the website: 13722360