Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- spam = ['apples', 'bananas', 'tofu', 'cats']
- def commaAnd(aList):
- aList.insert(-1, 'and')
- together = aList[0] #adds the first word without comma
- for i in range(len(aList) - 2): #-2 so that a comma does not follow 'and'
- together = together + ', ' + aList[i + 1] #adds commas after first word
- together = together + ' ' + aList[-1] #adds last word without comma
- print(together)
- commaAnd(spam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement