I'm doing an exercise from a python for beginners book. The project I'm stuck on is as follows: "Write a function that takes in a list of value as an argument and returns a string with all the items separated by comma and a space. Your function should be able to work with any list values passed to it"
Here is my code:
def passInList(spam):
for x in range(len(spam)):
z = spam[x] + ', '
print(z,end= ' ')
spam=['apples', 'bananas', 'tofu', 'and cats']
passInList(spam)
Expected output is - 'apples, bananas, tofu, and cats'.
My output is- 'apples, bananas, tofu, and cats,'
The issue I'm having, is that I can't seems to get rid of the comma at the end of "cats".
Thanks for suggestions.