Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Create a function to join words with a separator

Write a function that joins a sequence of items into a single string using a provided separator.

Python practice6 minFunctions & ScopeBeginnerLast updated March 17, 2026

Problem statement

Create a function join_with_separator(words, sep) that takes an iterable of items (strings, numbers, etc.) and a separator string sep. The function should convert each item to its string representation and join them with the separator. If the iterable is empty, return an empty string. The function must accept lists, tuples, and other iterables.

Task

Implement join_with_separator(words, sep) that converts items to strings and joins them with sep. Handle empty sequences and different iterable types.

Examples

Join words with a space

Input

join_with_separator(['hello', 'world'], ' ')

Output

hello world

Each item is a string; they are joined with a single space.

Input format

An iterable (list/tuple/other) of items as the first argument and a string separator as the second argument.

Output format

A single string containing the joined items.

Constraints

Do not assume all items are strings. Convert items to strings before joining. The separator is always a string.

Samples

Sample 1

Input

join_with_separator(['a', 'b', 'c'], ',')

Output

a,b,c

The list items are joined by a comma.