Hi all,
I’m trying to solve the extra question in the lesson: 'working with dates and times in Python about which person had the longest total visit length.
Below code gives me time out issues or does not give the right results.
Can someone tell me why?
for row in potus:
end_date = row[3]
end_date = dt.datetime.strptime(end_date, "%m/%d/%y %H:%M")
row[3] = end_date
visitors = {}
for row in potus:
visitor = row[0]
if visitor not in visitors:
visitors[visitor] = 1
else:
visitors[visitor] += 1
for key in visitors:
total_time = dt.timedelta()
time_spent = dt.timedelta()
for row in potus:
person = row[0]
start_time = row[2]
end_time = row[3]
if person == key:
time_spent = end_time - start_time
total_time += time_spent
visitors[key] = total_time