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

C H
C H
6,587 Points

Dates and Times in Python: Timestamp Ordering challenge, what's wrong with my code?

I think I am close to figuring this out but I keep getting an error. I am wondering if my code can be altered to work properly, or should I go about this problem a different way?

timestamp.py
import datetime

def timestamp_oldest(*args):
  plist = []
  for arg in args:
    plist.append(arg)

  plist = plist.sort()
  return datetime.datetime.fromtimestamp(plist[0], tz= None)

1 Answer

akak
akak
29,445 Points

The .sort() method is in-place method, and returns None. So assigning it to variable will give you an error.

Go for:

import datetime

def timestamp_oldest(*args):
  plist = []
  for arg in args:
    plist.append(arg)

  plist.sort()
  return datetime.datetime.fromtimestamp(plist[0])

Also you don't need timezone at the end.

C H
C H
6,587 Points

Thank you! So simple, yet so annoying trying to figure it out.

Justo Montoya
Justo Montoya
3,799 Points

thank you. I was thrown off by the asterisk on *args. I thought that it was a tupple so I would need to unpack it first before appending to a list and sorting it.