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 trialAndrew Galloway
3,137 PointsWhy 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.
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
Courses Plus Student 26,868 PointsHi, 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.
Andrew Galloway
3,137 PointsAndrew Galloway
3,137 PointsThank you William Li :) That is very helpful.