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 trialC H
6,587 PointsDates 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?
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
29,445 PointsThe .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
6,587 PointsC H
6,587 PointsThank you! So simple, yet so annoying trying to figure it out.
Justo Montoya
3,799 PointsJusto Montoya
3,799 Pointsthank 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.