Advertisement
Guest User

Untitled

a guest
Jul 14th, 2015
1,821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. spam = ['apples', 'bananas', 'tofu', 'cats']
  2. def commaAnd(aList):
  3.     aList.insert(-1, 'and')
  4.     together = aList[0]                 #adds the first word without comma
  5.     for i in range(len(aList) - 2):     #-2 so that a comma does not follow 'and'
  6.         together = together + ', ' + aList[i + 1]   #adds commas after first word
  7.     together = together + ' ' + aList[-1]           #adds last word without comma
  8.     print(together)
  9. commaAnd(spam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement