Easy Ways for Python List Concatenate with Example Codes

In this article, we will learn easy ways on how Python List Concatenate with example codes to help you understand and learn quickly.

Python’s extensive built-in data structures enable programmers to write code efficiently and fast. In comparison to other data structures, list are one of the most often used data structures in Python programming.

However, this is due to the fact the list offers a variety of characteristics and is compatible with storing an enormous amount of data under a single variable.

Moving on, Python lists are used to store items that are all the same and to change those same items.

Meanwhile, Python List Concatenation is the process of merging all of the parts of a data structure together from beginning to end.

Also read: Lowercase Python String with Example Programs

Here’s the six ways to concatenate a list in python.

  • Naive Method
  • concatenation (+) operator
  • List Comprehension
  • extend() method
  • *’ operator
  • itertools.chain() method

This operation is useful when we have a number of lists of elements that need to be processed in a similar manner.

Using the Naive Method Python

The Naive method is we keep adding elements from the second list to the first list as we go through the second list.

This way, the first list will have all of the elements from both lists so that the append will be done.

Here’s an example of Naive Method:

list1 = [10, 11, 12, 13, 14] 
list2 = [15, 30, 40] 

print("List1 before Concatenation:\n" + str(list1))
for x in list2 : 

print ("Concatenated list using naive method :\n" + str(list1))


List1 before Concatenation:
[10, 11, 12, 13, 14]
Concatenated list using naive method :
[10, 11, 12, 13, 14, 15, 30, 40]

Using Concatenation operator (+) in Python

The '+' operator is used to concatenate two lists. It adds one list to the end of another list, creating a new list as a result. This is the most practical way to perform list concatenation. 

Example of Concatenation using operator:

list1 = [20, 21, 22, 23, 24] 
list2 = [25, 30, 42] 

res = list1 + list2 

print ("Concatenated list using  operator (+):\n" + str(res))


Concatenated list using operator (+):
[20, 21, 22, 23, 24, 25, 30, 42]

Using List Comprehension Python

Python’s List Comprehension can also concatenate lists. It is an alternative method to concatenate two lists in Python.

List comprehension is essential for the generation of elements of the list from an existing list.

It processes using a for loop and iteratively traverses the list’s elements. The subsequent inline for loop is comparable to nested for loops.

Example of List Comprehension:

list1 = [10, 11, 12, 13, 14] 
list2 = [20, 30, 42] 

res = [j for i in [list1, list2] for j in i] 

print ("Concatenated list Using List Comprehension:\n"+ str(res))


Concatenated list Using List Comprehension:
 [10, 11, 12, 13, 14, 20, 30, 42]

Using extend method python

The extend() method in Python can be used to concatenate two lists. The extend() function iterates over the provided parameter and adds the item to the list, hence linearly increasing the list.




list1 = [11, 12,13, 14, 15] 
list2 = [21, 22, 24] 
print("list1 before concatenation:\n" + str(list1))
print ("List1 after concatenation Using extend method:\n"+ str(list1))

All of the elements of list2 are combined to list1, so updating list1 and generating output below.


list1 before concatenation:
[11, 12, 13, 14, 15]
List1 after concatenation Using extend method:
[11, 12, 13, 14, 15, 21, 22, 24]

Using Python ‘*’ operator

Python’s '*' operator can be used to concatenate two lists in Python easily. Python’s ‘*‘ operator basically unpacks the collection of objects specified by the index parameters. This feature was introduced in version 3.6.

Using the * operator allows us to concatenate multiple list into one list.

For instance[*list1, *list2] – concatenates the items in list1 and list2, and new list is created.

For example: Consider a list my_list = [1, 2, 3, 4].

The statement *my_list would replace the list’s elements at their respective index locations. Therefore, it unpacks the list of items.

Example program:

list1 = [10, 11, 12, 13, 14] 
list2 = [20, 30, 42] 

res = [*list1, *list2] 
print ("Concatenated list Using Python ‘*’ operator:\n " + str(res))


Concatenated list Using Python ‘*’ operator:
 [10, 11, 12, 13, 14, 20, 30, 42]

Using python itertools chain

itertools module possesses the in-built function “chain()” which helps simply combining lists. The itertools.chain() method accepts multiple data structures and results in the linear sequence as the output.

The itertools.chain() method takes as input different types of iterables, such as lists, strings, tuples, etc., and returns a chain of them.

It concludes in a linear sequence that the data type of the items has no effect on how the chain() method operates.

It is important to keep in mind that the data type of the element does not have any effect on how the chain() method operates. Additionally, you need to import the itertools library through the “import” keyword, as seen in the example that follows:

Example of list itertools chain:

import itertools
list1 = [10, 11, 12, 13, 14] 
list2 = [20, 30, 42] 

res = list(itertools.chain(list1, list2)) 
print ("Concatenated list Using python itertools chain:\n " + str(res))


Concatenated list Using python itertools chain:
 [10, 11, 12, 13, 14, 20, 30, 42]


To summarize, we’ve learned and understood how to implement different ways of Python List Concatenate in this article.

We know that list are the most common data format in programming, and we frequently encounter the need to combine two or more lists.

This article presents six easy ways for concatenating lists in Python with complete examples and output. It is highly suggested that you learn and comprehend this technique for efficient programming.

Leave a Comment