Python Dates and Times in Python Let's Build a Timed Quiz App Timestamp Ordering

Max Palmer
Max Palmer
2,920 Points

arg 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!

timestamp.py
# 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]
Max Palmer
Max Palmer
2,920 Points

Have since updated the code. For clarity sake see below.

import datetime datetimes = []

def timestamp_oldest(*args):

for arg in args:
    arg = datetime.datetime.fromtimestamp(arg)
    datetimes.append(arg)
    return datetimes

datetimes.sort()

return datetimes[0]

1 Answer

Steven Parker
Steven Parker
201,913 Points

Having 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.