Currently working my way through this beginners book and have completed one of the practice projects \'Comma Code\' which asks the user to construct a program which:
That one wins for simplicity Hein.
Only, the author specified:
"your function should be able to work with any list value passed to it."
To accompany non strings, add str()
tags to al the [i] functions.
spam = ['apples', 'bananas', 'tofu', 'cats', 'bears', 21]
def pList(x):
for i in range(len(x) - 2):
print(str(x[i]) + ', ', end='')
print(str(x[-2]) + ' and ' + str(x[-1]))
pList(spam)