Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 7, 2016 22:49
Show Gist options
  • Save Gwith/1faab1d28ba6c348440d1fa657cda60d to your computer and use it in GitHub Desktop.
Save Gwith/1faab1d28ba6c348440d1fa657cda60d to your computer and use it in GitHub Desktop.
spam = ['apples', 'bananas', 'tofu', 'cats']
def pretty_join(words):
if len(words) == 1:
return words[0]
else:
comma_separated = ", ".join(words[:-1])
last_word = words[-1]
return "{0}, and {1}".format(comma_separated, last_word)
print(pretty_join(spam))
input("enter to quit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment