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
Javier Perez Narvaez
15,007 PointsTIMESTAMP FUNCTION
Hi Team, please I need information on how the timestamp function works...
from datetime import datetime
def timestamp_oldest(list_stamp):
for x in range(len(list_stamp)):
list_temp = [0]
dt_object = datetime.fromtimestamp(float(list_stamp[x]))
list_temp = dt_object.append
timestamp = list_temp.sort()
return timestamp[0]
2 Answers
Javier Perez Narvaez
15,007 PointsHi, i'm confused how timestamp works!!!!!!
jb30
45,415 PointsTo convert POSIX time to datetime, you can use datetime_variable = datetime.datetime.fromtimestamp(posix_variable) where posix_variable is a POSIX timestamp.
In the line def timestamp_oldest(list_stamp):, you have a single parameter named list_stamp. The challenge wants the function to be able to take any number of arguments, such as by using *args. args would then be a tuple containing all of the POSIX timestamps. You can convert a tuple to a list by calling list(args).
To create an empty list, you can set list_temp = [].
You don't need to use append in this challenge if you convert your arguments to a list directly, but if dt_object has the method append, the line list_temp = dt_object.append will set list_temp to the built-in method append of the class of dt_object. To append the value of dt_object to list_temp, you could do list_temp.append(dt_object).
In the line timestamp = list_temp.sort(), list_temp becomes sorted and timestamp is of NoneType. If you want timestamp to be a reference to a sorted list and list_temp to be an unsorted list, you could do
timestamp = list_temp[:]
timestamp.sort()