Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) 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,248 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,271 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.