Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- spam = ['apples', 'bananas', 'tofu', 'cats']
- # write a program that takes a list of any size and seperates it's items with a comma and a space and returns it.
- #with an and on the last item.
- #in this case it should return 'apples, bananas, tofu, and cats'
- def split_list(your_list):
- for i in your_list:
- if your_list.index(i) < (len(your_list) - 1):
- return(str(i) + ', ')
- else:
- return('and ' + str(i))
- split_list(spam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement