Custom Separators and End Characters

Easy ⏱ 8 min 89% acceptance ★★★★★ 4.7
Write a function join_with(words, separator) that returns the strings in list words joined together using separator between each one (mirroring how print(*words, sep=separator) would display them, but returned as a string rather than printed).

Examples

Example 1
Input
join_with(["red", "green", "blue"], " - ")
Output
'red - green - blue'
Explanation

Elements joined with " - " between them.

Example 2
Input
join_with(["a"], ",")
Output
'a'
Explanation

Single element: no separator needed.

Constraints

  • words is a list of strings, possibly with one element; separator is a string.

Topics

Input & Outputprint() arguments

Companies

AmazonNetflix

Hints

Hint 1

`separator.join(words)` does exactly this.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.