Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. spam = ['apples', 'bananas', 'tofu', 'cats']
  2. # write a program that takes a list of any size and seperates it's items with a comma and a space and returns it.
  3. #with an and on the last item.
  4. #in this case it should return 'apples, bananas, tofu, and cats'
  5.  
  6.  
  7. def split_list(your_list):
  8. for i in your_list:
  9. if your_list.index(i) < (len(your_list) - 1):
  10. return(str(i) + ', ')
  11. else:
  12. return('and ' + str(i))
  13.  
  14. split_list(spam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement