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 trialMax Palmer
2,920 Pointsarg in args loop not working
For some reason the arg in args loop is not succesfully putting in the arguemnt to the append function.
I looked online and previous lessons but could not see why the arg loop would not be working.
Thanks in advance for help!
# If you need help, look up datetime.datetime.fromtimestamp()
# Also, remember that you *will not* know how many timestamps
# are coming in.
datetimes = []
def timestamp_oldest(*args):
for arg in args:
datetimes.append(arg)
return datetimes
datetimes.sort()
return datetimes[0]
1 Answer
Steven Parker
231,248 PointsHaving a 'return" inside the loop will cause the function to end during the first loop pass. It will never get a chance to repeat.
It also prevents any of the later code (like "sort") from being executed.
Max Palmer
2,920 PointsMax Palmer
2,920 PointsHave since updated the code. For clarity sake see below.
import datetime datetimes = []
def timestamp_oldest(*args):