Python Join List

Learn how to join a list in Python using str.join(), including lists of strings, numbers, mixed values, separators, newline joins, and common TypeError fixes.

Published

Updated

Read time 5 min read

Reviewed byDeepak Prasad

Python Join List

In everyday Python, “join a list” usually means either turning a list of strings into one string or merging lists into a longer list. Those are different operations. This page centers on str.join, which the docs describe as returning a string built from the strings in an iterable with your separator between them (and raising TypeError if any element is not a string). List-to-list tools such as +, extend(), and itertools.chain come second.

python
items = ["red", "green", "blue"]
print(" ".join(items))
Output

That prints red green blue. The separator (" ") is the string you call join on; the iterable holds the pieces.

Tested on: Python 3.13.3; kernel 6.14.0-37-generic.


Best way to join a list in Python

User wants Use
Join list items into a string ", ".join(items) (strings only)
Join list of numbers into a string ", ".join(map(str, numbers))
Join two lists into one list list1 + list2 (new list)
Add one list into another list1.extend(list2) (mutates first list)
Join many lists lazily itertools.chain(*lists)
Flatten one level of nested lists itertools.chain.from_iterable(nested) (see Python flatten list for deeper patterns)

Python join list syntax

text
separator_string.join(iterable_of_strings)

join is a string method: the separator is str, the iterable must yield str values. There is no list.join() API.


Join list of strings using join()

python
items = ["red", "green", "blue"]
print(" ".join(items))
Output

You should see red green blue.


Join list with comma separator

python
items = ["red", "green", "blue"]
print(",".join(items))
print(", ".join(items))
Output

The first line prints red,green,blue; the second prints red, green, blue.


Join list with space separator

python
words = ["hello", "world"]
print(" ".join(words))
Output

You should see hello world.


Join list with newline separator

python
lines = ["first", "second", "third"]
print("\n".join(lines))
Output

Running it prints three lines (first, then second, then third).


Join list of numbers

Numbers are not strings—convert before join:

python
numbers = [1, 2, 3]
print(", ".join(map(str, numbers)))
Output

You should see 1, 2, 3.


Join list with mixed data types

Cast each element to str (or normalize first) so join never sees non-strings:

python
mixed = ["id", 42, True]
print(" | ".join(str(x) for x in mixed))
Output

Expect id | 42 | True.


Fix TypeError when joining a list

TypeError: sequence item 0: expected str instance, int found means the iterable still holds non-strings.

python
numbers = [1, 2, 3]
result = ", ".join(map(str, numbers))
print(result)
Output

That prints 1, 2, 3. For richer objects, build the string you want explicitly instead of relying on str() defaults.


Join two lists in Python

Use + when you want a new combined list; use extend when you want to mutate the first list in place:

python
list1 = [1, 2]
list2 = [3, 4]
print(list1 + list2)

list1.extend(list2)
print(list1)
Output

The first print shows [1, 2, 3, 4] from a new list; list1 is still [1, 2] until extend runs. After extend(list2), list1 becomes [1, 2, 3, 4] while list2 remains [3, 4]. For more patterns, see Python concatenate lists.


Join list of lists in Python

For a single level of nesting, itertools.chain.from_iterable yields each inner item lazily, then you can join if those items are strings:

python
from itertools import chain

rows = [["a", "b"], ["c", "d"]]
print(",".join(chain.from_iterable(rows)))
Output

That prints a,b,c,d. Irregular trees or deeper nesting belong in a flattening workflow—use the dedicated Python flatten list guide instead of duplicating long recipes here.


join() vs + vs extend()

Tool Returns Typical use
sep.join(strings) One str Build text from string pieces
a + b New list Combine two lists immutably
a.extend(b) None (mutates a) Append all items from b into a

For strings, repeated result += chunk inside a tight loop allocates often; collecting pieces in a list and calling join once is usually faster and clearer.


Common mistakes when joining lists in Python

  • Writing items.join(", ")—the separator string must be the receiver: ", ".join(items).
  • Passing integers or objects straight into join—convert with map(str, ...) or comprehensions first.
  • Using join when you meant to merge two lists—join builds text, not a longer list.
  • Building big strings with + in a loop—prefer a list buffer plus one join.
  • Expecting a return value from extend()—it always returns None; the first list grows in place.
  • Calling str(my_list) when you wanted delimiter-separated output—you get bracket notation, not a tidy join.
  • Re-embedding a full flattening tutorial here—use the dedicated flatten-list guide linked in the table and nested-list section when nesting is the real problem.

Python join list quick reference table

Goal Pattern
CSV-like string ",".join(vals)
Human spacing ", ".join(vals) or " ".join(vals)
Multiline text "\n".join(lines)
Numeric list to text ", ".join(map(str, nums))
New combined list a + b
In-place merge a.extend(b)
One-level flatten then join sep.join(chain.from_iterable(groups))

Summary

Call separator.join(iterable) when every element is already a string; convert with map(str, ...) or explicit string formatting when you start from numbers or mixed types, because join raises TypeError otherwise. Comma, space, and newline joins are the same pattern with a different separator. When readers say “join lists” but mean list concatenation, switch to + or extend, and reach for itertools.chain or the flatten-list guide linked above when nested structure—not delimiter choice—is the hard part.


References


Frequently Asked Questions

1. Why do I get TypeError sequence item 0 expected str instance int found?

str.join expects every element to already be a string; convert with map(str, items) or a comprehension before calling join.

2. Do I call items.join(",") or ", ".join(items)?

The separator string is the receiver—write ", ".join(items) because join is a str method, not a list method.

3. Does join() merge two Python lists into one list?

No—it concatenates string elements into one str; use + or extend for list concatenation.

4. How do I flatten nested lists in depth?

Use itertools.chain.from_iterable for one level of nesting or follow a dedicated flattening guide for irregular trees.
Bashir Alam

Data Analyst and Machine Learning Engineer

Computer Science graduate from the University of Central Asia, currently employed as a full-time Machine Learning Engineer at uExel. His expertise lies in OCR, text extraction, data preprocessing, and …