Keep saying it does not have lenght

The problem:
Given a string called date that is in the form MM/DD/YYYY, write a function called date_extractor that takes date as an input and returns three values, month, day, and year.

For example, if date = '6/16/2006', the function should return multiple values in this form: ('6', '16', '2006').

Leave all returned values as strings.

My solution:

def date_extractor(date):
date_split = date.split(“/”)


Ouput: [‘01’, ‘19’, ‘1998’]

But, when I try to check answer it say that it does not have “length”, I can understand that is trying to say that I am not giving the answer as a string, but I do not know how to fix it and what could I be doing wrong, I have also tried .append the splits into strings to see if it works but haven’t find a way that it completly works, I usually say that i am out of reach, when I try to append the year information.

Have you worked with multiple return values, yet?

Also, your function is printing the values instead of returning them.

After saying that I was completely lost it all clicked.
The answer was:

def split_date(date): parts = date.split('/') if len(parts) == 3: day, month, year = parts return day, month, year

This way I have it returned as a string, and not just as a tuple.

You are not returning a single string (and the instructions don’t seem to want that anyway).

In your function, the variables day, month and year have strings assigned to them. But the return statement

return day, month, year

doesn’t concatenate/join them as a single string before returning. Since you are returning multiple values in a single return statement, so they are returned as a tuple.

You can verify it by doing something like:

result = split_date("01/19/1998")
print(result)  # ('01', '19', '1998')
print(type(result)) # <class 'tuple'>

In your original post, you were printing instead of returning. Also, the split method returns a list of strings. So, if you returned the whole list, the automated grader would probably reject the solution as it is likely expecting a tuple to be returned (based on the example in the instructions of your original post).

You could also have converted the list to a tuple explicitly before returning (but that decision depends on what you want to do in your function and what you find to be more readable),

def split_date(date):
    return tuple(date.split('/'))

result = split_date("01/19/1998")
# OR you can unpack the returned tuple to different variables
month, day, year = split_date("01/19/1998")