Garrowni / AutomateTheBoringStuff

Repo to house projects I complete from automate the boring stuff
0 stars 0 forks source link

Comma Code #3

Open Garrowni opened 1 year ago

Garrowni commented 1 year ago

Comma Code - https://automatetheboringstuff.com/2e/chapter4/ Say you have a list value like this:

spam = ['apples', 'bananas', 'tofu', 'cats']

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. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it. Be sure to test the case where an empty list [] is passed to your function.

Garrowni commented 1 year ago

Useful reference: https://docs.python.org/3/library/stdtypes.html