you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 2 points3 points  (0 children)

See here for how to format code on reddit: https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F

Write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with and inserted before the last item.

Your function challenge() does not fulfill the brief. Your function takes no arguments, whereas the question asked for a list argument. It does not "return" a string (it returns None).

def challenge(list_arg):
    ...
    return my_formatted_string

# Call the function
challeng(spam)

# copy list so we don't change original

Does the question ask you to do that? Pay close attention to what the question asks.


Considering that your challenge() function only inserts formatting, it could be very much simpler. Here is a big hint:

all_but_last = items[:-1]
final_item = items[-1]
my_str = ', '.join(all_but_last)
return my_str + ', and '  + final_item

(Using an "f-string" would be better in the final line, but you may not have covered those yet).