Question: Question 1b: The Best Words [4 points Write a function count_occurences (jsonurl, word) that counts the number of times that word occurs across all of

 Question 1b: The Best Words [4 points Write a function count_occurences

Question 1b: The Best Words [4 points Write a function count_occurences (jsonurl, word) that counts the number of times that word occurs across all of the given tveets. This should be case insensitive, but for simplicity, you only need to match whole words. Make sure you match whole words only, and not substrings. For example, if word "dont" , then "dont'. "DONT" and "dOnT" would all count, but "perioDONTal" should not. Remove all punctuation in the text of the tweet (if there is any). "dont should be correctly counted for word-"dont" In [1: from string import punctuation print( "Remove all of these symbols from the tweets: ", punctuation) In [3]: import json import urllib.request from string import punctuation def count_occurences (jsonurl, word): with urlopen("http://brain.mcmaster.ca/joey/trump_tweets.json") as response: source response. read() data = json.loads(source) for q in data: for w in y: for i in w['text'].split(,"): y=y+[i] for wq in s: if word in wq. lower): x=x+1 return x # Write your answer here In [4] : count occurences('http://brain . mcmaster.ca/Joey/trump-tweets. Json, .crooked.) 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!