Transforms ("a", "b", "c") into "a, b and c" string
(words)
| 1 | def formatList(words): |
| 2 | """Transforms ("a", "b", "c") into "a, b and c" string""" |
| 3 | if not words: |
| 4 | return "" |
| 5 | if len(words) == 1: |
| 6 | return words[0] |
| 7 | last = words[-1:][0] |
| 8 | beginning = ", ".join(words[:-1]) |
| 9 | return "{0} and {1}".format(beginning, last) |