Question
1. Please write the followng programs in Python 3 and please answer the questions. Also, please share code and show all ouputs. PLEASE ANSER ALL
1. Please write the followng programs in Python 3 and please answer the questions. Also, please share code and show all ouputs. PLEASE ANSER ALL QUESTIONS BASED ON THE PROGRAM. I HAVE GIVEN HINTS TO HELP.
(1 point)
Now, before we can count the instances of a list of words of interest, we need to prepare the words. All that punctuation gets in the way -- caterpillar is not the same as caterpillar, So, lets dump all the punctuation.
But watch out!!! Some of the punctuation is necessary! Blindly removing all punctuation without caution will produce erroneous counts. As written, double-hyphen -- is used without space between words, so deleting a single hyphen removes double-hyphens, too, accidentally concatenating words!
Write a function called depunctify() that takes in a string, and returns a new string that contains only alphanumeric characters and whitespace. Be sure to deal with the double-hyphen problem; replace -- with a single space.
How long is the resulting string for Alice in Wonderland? -PLEASE ANSWER
HINT PROGRAM TO BE MODIFIED:
Heres the code I used:
def depunctify(text): text = text.replace('--',' ') for p in string.punctuation + "": text = text.replace(p,'') return text alice_no_punct = depunctify(alice) len(alice_no_punct)
-----------------------------------------------------------------
We have the text without punctuation. Great! We want to count words. In english, we Capatalize To Indicate Importance. But, Python string comparison is case-sensitive, so we need to correct that, too. Also, the newlines in the string are making this hard to look at for me.
Write a new function called canonicalize(...) that takes a string,
de-punctifies it, (use your function from previous problem)
replaces newlines with a space (why wouldnt we just delete the newlines?), and
de-capitalizes it.
Call the function on Alice in Wonderland.
At this point, how many characters are in this text? PLEASE ANSWER THIS QUESTION ALSO:
Did we remove or add any characters in this function?
Heres the code I used:
def canonicalize(text): text = depunctify(text) text = text.replace(' ',' ') text = text.lower() return text
_________________________________________________________________
Now that weve got Alice in Wonderland in memory as a string with just letter, numbers, and space, we need the list of words.
Fortunately, Python has tons of utilities for working with strings built in! Were going to do this in one line of code.
Write one line of code that takes the cleaned-up string and produces a list of all the words (with duplicates) in the string.
What is the number of words in Alice in Wonderland? (or at least, this way of processing it) PLEASE ANSER THIS QUETION
__________________________________________________________________________________
We have the text without punctuation. Great! We want to count words. In english, we Capatalize To Indicate Importance. But, Python string comparison is case-sensitive, so we need to correct that, too. Also, the newlines in the string are making this hard to look at for me.
Write a new function called canonicalize(...) that takes a string,
de-punctifies it, (use your function from previous problem)
replaces newlines with a space (why wouldnt we just delete the newlines?), and
de-capitalizes it.
Call the function on Alice in Wonderland.
At this point, how many characters are in this text? PLEASE ANSEWR THIS QUESTION
______________________________________________________________________________
Now that weve got Alice in Wonderland in memory as a string with just letter, numbers, and space, we need the list of words.
Fortunately, Python has tons of utilities for working with strings built in! Were going to do this in one line of code.
Write one line of code that takes the cleaned-up string and produces a list of all the words (with duplicates) in the string.
What is the number of words in Alice in Wonderland? (or at least, this way of processing it) PLEASE ANSER THIS QUESTION
___________________________________________________________________________________________
Were at the end of our little journey together! We have a list of all the words in the book, a list of words of interest, and an empty set of counters.
Write a bit of Python code that combines these ingredients, and gives the number of times each word of interest appears in Alice in Wonderland. Again, the built-in utilites of Python make this, after you know how to do it, a snap.
How many times does dark appear? PLEASE ANSER THIS QUESTION
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