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 trialMUZ140502 Natasha Hove
3,732 PointsCreate a function named timestamp_oldest that takes any number ofPOSIX timestamp arguments.
I am getting 'Try again' error...Where am i getting it wrong??
# If you need help, look up datetime.datetime.fromtimestamp()
# Also, remember that you *will not* know how many timestamps
# are coming in.
import random
import datetime
def timestamp_oldest(args):
oldest = datetime.datetime.now()
for arg in args:
oldest > datetime.datetime.fromtimestamp(arg)
return oldest
1 Answer
William Li
Courses Plus Student 26,868 PointsHi, Natasha Hove
Create a function named timestamp_oldest that takes any number of POSIX timestamp arguments. Return the oldest one as a datetime object.
- to convert a POSIX timestamp to datetime object, we can make use of the
datetime.datetime.fromtimestamp()
method from datetime module, which you got it right. - then, this function accepts ANY number of arguments, and stores them in the
*args
tuple, the challenge gave you a hint here
Remember, POSIX timestamps are floats and lists have a .sort() method.
But the easiest way to pick out the oldest POSIX timestamp from the tuple is using min()
method.
To put everything together.
import datetime
def timestamp_oldest(*args):
return datetime.datetime.fromtimestamp(min(args))
Hope this helps.
Adam Teale
10,989 PointsAdam Teale
10,989 PointsThat's cool! Thanks for sharing
Stephen Lorenz
3,271 PointsStephen Lorenz
3,271 Pointswow! I didn't realize it was that simple!
my code was saying it wasn't returning the right value, what's going on?
def timestamp_oldest(*args):