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 trialAnton Tskhay
2,344 Pointscan't solve this(
Could anybody help with the task?
# If you need help, look up datetime.datetime.fromtimestamp()
# Also, remember that you *will not* know how many timestamps
# are coming in.
import datetime
def timestamp_oldest(*args):
oldest = timestamp_oldest[0]
for var in *args:
if var < oldest:
oldest = var
return oldest
2 Answers
boi
14,242 PointsThe challenge can be solved in 4 steps.
Step1: Create a function that accepts any number of arguments.
def timestamp_oldest(*args):
Step2: Since we do not know how many arguments will be given, we'll create a list and append all the arguments into that.
timestamps = []
for value in args:
timestamps.append(value)
Step3: We need to sort the list to get the smallest number because the smallest number is the closest to the EPOC time.
timestamps.sort()
Step4: Let's now convert the POSIX timestamp to a Datetime timestamp by using fromtimestamp()
method.
return datetime.datetime.fromtimestamp(timestamps[0])
If you need more clarification let me know.
Anton Tskhay
2,344 PointsI've got it, thank you so much