How to Concatenate Two Lists in Python
Introduction
List concatenation the act of creating a single list from multiple smaller lists by daisy chaining them together.
There are many ways of concatenating lists in Python. Specifically, in this article, we’ll be going over how to concatenate two lists in Python using the plus operator, unpack operator, multiply operator, manual for loop concatenation, the itertools.chain()
function and the inbuilt list method extend()
.
In all the code snippets below, we’ll make use of the following lists:
list_a = [1, 2, 3, 4]
list_b = [5, 6, 7, 8]
Plus Operator List Concatenation
The simplest and most straightforward way to concatenate two lists in Python is the plus (+
) operator:
list_c = list_a + list_b
print (list_c)
[1, 2, 3, 4, 5, 6, 7, 8]
Unpack Operator List Concatenation
This method allows you to join multiple lists. It is a