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

Why is *args coming through as a tuple instead of a list?

My function can't sort the provided input and I have no idea why.

timestamp.py
import datetime

def timestamp_oldest(*args):
    timestamps = list()
    for n in args:
        timestamps.append(datetime.datetime.fromtimestamp(n))
    timestamps = timestamps.sort()
    return min(timestamps)

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, Andrew, Yes, the args always come through as tuple.

For this challenge, there're two approaches: 1. convert the tuple into list using the list() function, sort it, then the 1st item on the sorted list is the smallest; 2. Python has a built-in min() function, when passing in tuple as argument to this function, it'd returns the smallest item on the tuple.

Return the oldest one as a datetime object.

after you pick out the smallest element from the tuple, the final step is pass it as argument to datetime.datetime.fromtimestamp() to convert it to datetime object.

import datetime

def timestamp_oldest(*args):
  return datetime.datetime.fromtimestamp(min(args))

Hope it helps.

Thank you William Li :) That is very helpful.