Exercise Finding the Last Sessions: my answer not matching DQ's result

Screen Link: https://app.dataquest.io/m/1000353/working-with-dates-and-times-in-python-practice-problems/9/finding-the-last-session

My Code:

import datetime as dt

# Write your solution below
f = open('session_log.csv')
reader = csv.reader(f)
rows = list(reader)[1:]

time_list = []
max_time = None
latest_session_user_id = None 

for row in rows:
    row = [int(x) for x in row]
    start = dt.datetime(row[1],row[2],row[3],row[4],row[5])
    time_list.append(start)
    if start == max(time_list):
        latest_session_user_id = row[0]
        max_time = start 
    
latest_start_str = max_time.strftime("%Y/%m/%d %H:%M")

What I expected to happen:
Match the correct answer

What actually happened:

Error: latest_session_user_id is greater than what we expected.

My code says the latest date is “‘2020/01/01 23:50’”
DQ’s answer says the latest date is ‘2020/01/02 09:37’
I downloaded the csv and the latest date as per DQ is missing in that file from the exercise.

This is the required task -

In this practice problem, we want you to identify the row corresponding to the last session. In other words, the session with the latest end time (counting both the date and hour).

Your code -

Those indices don’t correspond to the latest end time. They correspond to the session start time. Fixing that should give you the correct result.

1 Like

Thank you. I couldn’t spot that one.