(items)
| 3 | |
| 4 | # Join a list into a comma-separated English string |
| 5 | def comma_code(items): |
| 6 | item_len = len(items) |
| 7 | |
| 8 | # Return empty string for empty list |
| 9 | if item_len == 0: |
| 10 | return "" |
| 11 | elif item_len == 1: |
| 12 | return items[0] |
| 13 | |
| 14 | # Join all but last, then append "and <last>" |
| 15 | return ", ".join(items[:-1]) + ", and " + items[-1] |
| 16 | |
| 17 | |
| 18 | if __name__ == "__main__": |