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 trialJonathan Shedd
1,921 PointsDon't know what's wrong with this code involving fromtimestamp()
I keep getting the error: "NoneType is not subscriptable". Not sure exactly what this means. If anyone could explain what is wrong with my code that would be a huge help! Thanks!
# 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):
my_list_of_stamps = list(args)
my_list_of_stamps = my_list_of_stamps.sort()
return(datetime.datetime.fromtimestamp(my_list_of_stamps[0]))
1 Answer
Steven Parker
231,269 PointsThe sort method does not return a value.
So the value your variable gets from the assignment is None, and then trying to get the "[0]" element from None produces that error.
But the sort method does modify the list it is used on:
# my_list_of_stamps = my_list_of_stamps.sort() <- instead of this
my_list_of_stamps.sort() # ...do this
Jonathan Shedd
1,921 PointsJonathan Shedd
1,921 PointsThank you so much! I got it figured out now. :)
Brent Liang
Courses Plus Student 2,944 PointsBrent Liang
Courses Plus Student 2,944 PointsThank you Steven for the answer! Helpful. And thank you Jon for asking the question!!
Mduduzi Frederick Dube
8,886 PointsMduduzi Frederick Dube
8,886 PointsRight sort does not return a value, hey Thanks Mr Parker.