Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Plz tell me what is wrong with my code. why my code doesn't read the items in list_of_words. when i test my code it returns
Plz tell me what is wrong with my code. why my code doesn't read the items in list_of_words. when i test my code it returns false for all the items that are in the list.
I suspect that the list should be separated by commas and quotation marks (maybe i am wrong) but i don't know how to implement it.
I appreciate your help
The following list is save in a list_of_verbs.txt
['Accept Achieve Add Admire Admit Adopt Advise Agree Allow Announce Appreciate Approve Argue Arrive Ask Assist Attack Bake Bathe Be Beat Become Beg Behave Bet Boast Boil Borrow Breathe Bring Build Burn Bury bury Buried Burying Buy Call Catch Challenge Change Cheat Chew Choose Clap Clean Collect Compare Complain Confess Confuse Construct Control Copy Count Create Cry Damage Dance Deliver Destroy Disagree Drag Drive Drop Earn Eat Employ Encourage Enjoy Establish Estimate Exercise Expand Explain Fear Feel Fight Find Fly Forget Forgive Fry Gather Get Give Glow Greet Grow Guess Harass Hate Hear Help Hit Hope Identify Interrupt Introduce Irritate Jump Keep Kick Kiss Laugh Learn Leave Lend Lie Like Listen Lose Love Make Marry Measure Meet Move Murder Obey Offend Offer Open Paint Pay Pick Play Pray Print Pull Punch Punish Purchase Push Quit Race Read Relax Remember Reply Retire Rub See Select Sell Send Sing Snore Stand Stare Start Stink Study Sweep Swim Take Talk Teach Tear Tell Thank Travel Type Understand Use Visit Wait Walk Want Warn Wed Weep Wink Worry Write Yell']READING FROM A FILE Copy the above list of verbs into a file called list_of_verbs.txt. Save this file at the same location as Assignment-2.ipynb , then execute the following code cell. In [92]: ['Accept Achieve Add Admire Admit Adopt Advise Agree Allow Announce Appreciate Approve Argue Arrive Ask Assist Attack Bake B athe Be Beat Become Beg Behave Bet Boast Boil Borrow Breathe Bring Build Burn Bury bury Buried Burying Buy Call Catch Challe nge Change Cheat Chew Choose Clap Clean Collect Compare Complain Confess Confuse Construct Control Copy Count Create Cry Dam age Dance Deliver Destroy Disagree Drag Drive Drop Earn Eat Employ Encourage Enjoy Establish Estimate Exercise Expand Explai n Fear Feel Fight Find Fly Forget Forgive Fry Gather Get Give Glow Greet Grow Guess Harass Hate Hear Help Hit Hope Identify Interrupt Introduce Irritate Jump Keep Kick Kiss Laugh Learn Leave Lend Lie Like Listen Lose Love Make Marry Measure Meet Mo ve Murder Obey offend Offer Open Paint Pay Pick Play Pray Print Pull Punch Punish Purchase Push Quit Race Read Relax Remembe r Reply Retire Rub See Select Sell Send Sing Snore Stand Stare Start Stink Study Sweep Swim Take Talk Teach Tear Tell Thank Travel Type Understand Use Visit Wait Walk Want Warn Wed Weep Wink Worry Write Yell'] CREATING A SET OF RULES Use Table 4.2 (from https://www.nltk.org/book/ch01.html) to create some potential rules/characteriztics for identifying whether a word is a verb. For example, if the word ends in ing then it can be considered a verb. Another simple rule to implement is to see if the word is in our list_of_verbs . \begin{tabular}{c|c} In [96]: N & list_of_verbs = read_list_of_verbs_from_file() \\ def is_word_a_verb(word): \\ if word in list_of_verbs: \\ return True \\ else: \\ return False \end{tabular} DATA TO TEST PERFORMANCE OF CODE An example of what the test data could look like is the following list of words: testing_data = [ "Drag", "Drive", "Accept", "crying", "Find", "kiss", ] for word in testing_data: result = is_word_a_verb(word) print(f" { word } \{result } ") Drag: False Drive: False Accept: False crying: False Find: False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started