Create 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
William LiCourses Plus Student 26,837 Points
Hi, 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
*argstuple, 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
To put everything together.
import datetime def timestamp_oldest(*args): return datetime.datetime.fromtimestamp(min(args))
Hope this helps.