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

Function comma_code

web/public/playground/comma-code.py:5–15  ·  view source on GitHub ↗
(items)

Source from the content-addressed store, hash-verified

3
4# Join a list into a comma-separated English string
5def 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
18if __name__ == "__main__":

Callers 1

comma-code.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected