Easy Ways for Python List Concatenate with Example Codes

Python List Concatenate

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.

Here are 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 : 
    list1.append(x) 


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

Output:

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))

Output:

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))

Output:

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.

Syntax:

list.extend(iterable)

Example:

list1 = [11, 12,13, 14, 15] 
list2 = [21, 22, 24] 
print("list1 before concatenation:\n" + str(list1))
list1.extend(list2) 
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.

Output:

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 lists 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))

Output:

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

Using Yython 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))

Output:

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

Conclusion

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

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

Six easy ways for concatenating lists in Python with complete examples and output are already given above.

It is highly suggested that you learn and comprehend this technique for efficient programming.

Related Python Tutorials

Common use cases for Easy Ways for Python List Concatenate

  • Data pipelines. Python is the standard for ETL, data analysis, and ML workflows.
  • Web development. Django and FastAPI power modern web backends and APIs.
  • Automation and scripting. System administration, file processing, web scraping, and cron jobs.
  • Machine learning. scikit-learn, PyTorch, TensorFlow, Hugging Face for AI/ML projects.
  • Educational tools. Python’s readability makes it the go-to teaching language.

Working code example

from typing import Optional

def process_data(items: list[dict]) -> Optional[dict]:
    """Process a list of items and return summary stats."""
    if not items:
        return None
    return {
        "count": len(items),
        "total": sum(item.get("value", 0) for item in items),
        "avg": sum(item.get("value", 0) for item in items) / len(items),
    }

# Usage
data = [{"value": 10}, {"value": 20}, {"value": 30}]
summary = process_data(data)
print(summary)  # {'count': 3, 'total': 60, 'avg': 20.0}

Best practices

  • Use type hints. list[dict], Optional[str], and TypedDict make code self-documenting and enable static analysis.
  • Follow PEP 8. Consistent style improves readability. Use black or ruff to auto-format.
  • Prefer f-strings. f”{value}” is cleaner than str.format() or % formatting.
  • Write tests with pytest. Aim for 70%+ coverage on business-critical modules.
  • Use ruff or pylint. Static analysis catches many bugs before code runs.

Common pitfalls

  • Mutable default arguments. def f(x=[]) reuses the same list across calls. Use x=None then check.
  • Integer division. 5/2 gives 2.5 in Python 3. Use // for floor division.
  • Missing self on methods. Class methods need self as first parameter.
  • Late binding closures. Loops that create lambdas can capture variables late.

Frequently Asked Questions

What Python version does this tutorial target?
This tutorial targets Python 3.10 or higher. Most examples work on 3.8+, but newer features (match statements, pipe union types, structural pattern matching) need 3.10+. For deep learning content, Python 3.11 is recommended for best performance.
How do I install Python for this tutorial?
Download Python 3.11 or higher from python.org. On Windows, tick ‘Add to PATH’ during install. On Mac use Homebrew (brew install python). On Linux use your package manager or pyenv for version management.
Do I need pip and virtual environments?
Yes. pip comes with Python. For any project beyond a single script, create a virtual environment: python -m venv venv, then activate and pip install dependencies. This keeps project libraries isolated.
Can I use this in a Jupyter notebook or Google Colab?
Most examples run in both. Colab is great for ML tutorials since it provides free GPU access. Jupyter is better for local iterative development. Just paste the code into a cell and run.
Where can I find more Python practice projects?
Browse itsourcecode.com Python Projects for 250+ free capstone-ready systems (sentiment analysis, image classification, chatbots, LangChain apps). Each includes full source code, dataset links, and installation instructions.

Caren Bautista


Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel
 · View all posts by Caren Bautista →

Leave a Comment