Question: please answer in python Consider the string S defined in the cell below (borrowed from the New York Times). Please process this string in the
please answer in python
Consider the string S defined in the cell below (borrowed from the New York Times). Please process this string in the following ways. (This tutorial might be helpful.) Please make the result of each part clear and easy to see 1. Convert the string to only lowercase letters (let the result be called S1). Hint: there is a built-in string method that does this) 2. Remove all non-alphabetical characters from S1 except for spaces (let the result be called S2) 3. Use the split) method on S2 to produce a list L of words occurring in S 4. By using the python set type, produce a set W of all the unique words occurring in L. What is the ratio of the length of W to the length of L 5. Use W to produce a list W S of the words in W occurring in sorted order 6. Create a function word-vector (WS, L) that takes WS and L as input and returns a numpy array N of length len (WS) such that for each in range ( len (WS) ) , N[i] is equal to the number of times the word WS[i] occurs in L. 7. Create a function cos_sim(N,M) that computes the cosine similarity of two word vectors (two outputs from word_vector called N and M). Type Markdown and LaTeX: 2 In [17 S-A deep, brutal cold set in across the Midwest on Wednesday, sending temperatures plummeting to depths that stunned even Midwesterners, a group accustomed to shrugging off winter. The cold that seized the middle of the country was the sort that makes cars moan, that makes breathing hurt, that makes any bit of exposed skin sting. Cities like Chicago had been preparing for the deep freeze for days, so when it arrived, much of life had come to a standstill. Colleges and schools were closed all around, and even the United States Postal Service had stopped deliveries in some places. Workers were sent home, meetings canceled, parties called off. And the worst of the blast was still to come: Forecasters said temperatures would drop again after sunset on Wednesday, and that Chicago might even break its record low of minus 27 The outlook for Thursday was different but still grim: slightly warmer temperatures-and snow A deep, brutal cold set in across the Midwest on Wednesday, sending temperatures plummeting to depths that stunned even Midwesterners, a group accustomed to shrugging off winter. The cold that seized the middle of the country was the sort that makes cars moan, that makes breathing hurt, that makes any bit of exposed skin sting.InnCities like Chicago had been preparing for the deep freeze for days, so when it arrived, much of life had come to a standstill. Colleges and schools were closed all around, and even the United States Postal Service had stopped deliveries in some places. Workers were sent home, meetings canceled, parties called offIninAnd the worst of the blast was still to come: Forecasters said temperatures would drop again after sunset on Wednesday, and that Chicago might even break its record low of minus 27. The outlook for Thursday was different but still grim: slightly warmer Out[17): temperatures-and snow
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
