Combines list into a string of the form item1, item2, and item 3 Args: items (list): List of strings Returns: string: list items combined into a string
(items)
| 1 | def comma_code(items): |
| 2 | """Combines list into a string of the form item1, item2, and item 3 |
| 3 | Args: |
| 4 | items (list): List of strings |
| 5 | |
| 6 | Returns: |
| 7 | string: list items combined into a string |
| 8 | """ |
| 9 | item_len = len(items) |
| 10 | |
| 11 | if item_len == 0: |
| 12 | return "" |
| 13 | elif item_len == 1: |
| 14 | return items[0] |
| 15 | |
| 16 | return ", ".join(items[:-1]) + ", and " + items[-1] |
| 17 | |
| 18 | |
| 19 | if __name__ == "__main__": |