-
-
Save Gwith/1faab1d28ba6c348440d1fa657cda60d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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