LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

White House Visitors: Who Was There the Most and Who Spent the Most Time Visiting?

If anyone has analyzed who spent the most time in the White House, and who visited the most, please let me know what you think about my findings and code below. Thank you!

====================== ======================== ==========================

#Who visited the White House the most?
#Create a frequency table, with a dictionary containing names

visitors = {}
for row in potus:
name = row[0]
if name in visitors:
visitors[name] += 1
else:
visitors[name] = 1

print("Vistor: ", sorted(visitors.items(), key=lambda x: x[1], reverse=True))
====================== ======================== ==========================
#Who spent the most amount of time in the White House?
visitor_time = {}
for row in potus:
v_name = row[0]
start_time = row[2]
end_time = row[3]
visit_time = end_time - start_time
if v_name in visitor_time:
visitor_time[v_name] += visit_time
else:
visitor_time[v_name] = visit_time

sorted_visits = sorted(visitor_time.items(), key=lambda x: x[1], reverse=True)

print(sorted_visits)

============
My Answers: ‘Alan C. Prather’, datetime.timedelta(days=29, seconds=59280)
and ‘Alan C. Prather’ with 32 visits.