MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / comma_code

Function comma_code

projects/comma-code/comma-code.py:1–16  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1def 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
19if __name__ == "__main__":

Callers 1

comma-code.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected