Guest User

commaCode

a guest
Jul 7th, 2015
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. spam = ['apples','bananas', 'tofu','cats']
  2. newString = None
  3.  
  4. def listToString(list):
  5. list.insert(-1,'and')
  6. newString = str(list)
  7. newString = newString[1:-1]
  8. for i in range(0,len(newString)):
  9. newString = newString.replace("'",'')
  10. n = newString.rfind(",") #finds the highest index that contains a comma
  11. newString = newString[:n] + newString[n+1:] #concactenate to remove comma
  12. print(newString)
  13.  
  14. listToString(spam)
Advertisement
Add Comment
Please, Sign In to add comment