Python Practice › List Programs › Program 31

Join elements with a special character

EasyList Programs · 31 of 100

Write a Python program to merge all elements of a list into one string using a special character.

Advertisement
Input
["sqa", "tools", 2026, "python"], separator "#"
Output
sqa#tools#2026#python

Approach

  1. Convert each item to str and join with the separator.

Solution

Python
items = ["sqa", "tools", 2026, "python"]print("#".join(str(x) for x in items))
Output
sqa#tools#2026#python

Line by line

Line 2

join only accepts strings, so the number is converted first.

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs

Leave a Comment