Question: Program 1: import json import time start_time = time.time() tweets = [] # Read each file and parse the Tweet JSON object for i in
Program 1:
import json
import time
start_time = time.time()
tweets = []
# Read each file and parse the Tweet JSON object
for i in range(1, 4):
with open("TweetsDataPart{}.txt".format(i)) as f:
for line in f:
tweet = json.loads(line)
tweets.append({
"created_at": tweet["created_at"],
"screen_name": tweet["user"]["screen_name"],
"text": tweet["text"]
})
# Save the output to a file
with open("output.txt", "w") as f:
for tweet in tweets:
f.write("{} {} {} ".format(
tweet["created_at"],
tweet["screen_name"],
tweet["text"]
))
print("Time taken: {:.9f} seconds".format(time.time() - start_time))
Program 2: Redo Program 1 by utilizing a multithreading approach. Report the total time in seconds needed to generate this output file from start reading the input files until finish writing the output file. and compare it with the total time from Program 1. Report how much this approach is faster than the one in Program 1 ? Write your answer as a comment in the python file
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
