Created
August 7, 2016 20:22
-
-
Save Gwith/adcf1294047ac784fc8664a70a643a68 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 comma(a_list): | |
last = a_list[-1] | |
all_but_last = a_list[0:-1] | |
result = '' | |
for item in all_but_last: | |
result += item | |
result += ', ' | |
result += 'and ' | |
result += last | |
print(result) | |
comma(spam) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment