CJCoding With Joseph
15free / daySign inCreate account

Join Words With Commas

Write join_words(words: list[str]) -> str that returns the words joined into one string with a comma and a space between each pair, and nothing after the last word, by recursion and without .join(): a list of exactly one word returns that word; otherwise the result is the first word, then ", ", then the joined rest of the list (the slice words[1:]). Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of words separated by spaces, at least one, which the tests read into a list and pass to your function before printing the string it returns.

Expected Output:

red, green, blue

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
RecursionSlicing
📥 Auto-Input:
red green blue\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.