Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python Let's Build a Timed Quiz App Timestamp Ordering

Holden Glass
Holden Glass
6,077 Points

Don't know how to get enough place holders in timestamp_oldest

I get the question but the only part I don't get is how to be able to get all the timestamps into the function. Advise would be much appreciated.

timestamp.py
# If you need help, look up datetime.datetime.fromtimestamp()
# Also, remember that you *will not* know how many timestamps
# are coming in.

import datetime

def timestamp_oldest(time_stamps):
    time_stamps.sort()
    return incoming[:len(incoming)-2:-1]

3 Answers

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,236 Points

There are a few things you need to look at.

You are taking mutiple timestamps, you dont know how many, so you need the *args

def timestamp_oldest(*args):

You need to create a list of time stamps

    time_stamps=[]
    for ea in args:
        time_stamps.append(ea)

You need to sort the list, the oldest will be first. So return the first record.

    time_stamps.sort(reverse=True)
    return datetime.datetime.fromtimestamp(time_stamps[1])
james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

it tells you lists have a sort method, so it's going to call your function with a list of timestamps as the argument. your function needs to sort these and return the oldest one. they are floats so sorting from lowest to highest would put the oldest (lowest) one at index 0 in the list, then just return that as a datetime object as requested.

Holden Glass
Holden Glass
6,077 Points

I tried just putting in a single argument and it said that the function took one argument and it was given eight.