Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Concatenate or Join Two Lists in Python

  • 25 Nov, 2025
  • Com 0
Merging Two Lists in Python

Joining two (or more) lists involves combining the elements of two or more lists into a single, unified sequence.

Here are different ways based on various scenarios:

Method 1: Using the standard operator (+)

Joining Two Lists in Python with + operator

The most intuitive method for concatenating two lists is the + operator in Python. It creates a new list containing the elements of the first list, followed by those of the second.

Here is the basic syntax:

new_list = list1 + list2

It does not modify the original lists. It allocates new memory for the result.

list1 = [11, 21, 19]
list2 = [4, 5, 6]

# Creates a completely new object
merged_list = list1 + list2

print(merged_list)
# Output: [11, 21, 19, 4, 5, 6]

print(list1)
# Output: [11, 21, 19] (remains unchanged)

If the memory usage is not your primary concern, you can opt for this approach. However, it only works for lists and not for other types.

list1 = [11, 21, 19]

merged_list = list1 + (4, 5, 6)

print(merged_list)

# TypeError: can only concatenate list (not "tuple") to list

Handling None

If one of your variables is None rather than an empty list [], concatenation will crash.

a = [1, 2]
b = None

result = a + b  # Raises TypeError

print(result)

# TypeError: can only concatenate list (not "NoneType") to list

For safe concatenation, you can use a list comprehension.

a = [1, 2]
b = None

result = a + (b if b is not None else [])

print(result)

# Output: [1, 2]

Method 2: Using a list.extend()

Merging Two Lists in Python with list.extend() method

If you want to modify an existing list and do not care for a new list, use the built-in list.extend() method. It is the most efficient method for in-place concatenation.

The extend() method adds the second list to the tail end of the first list.

list1 = [11, 21, 19]
list2 = [4, 5, 6]

list1.extend(list2)  # This modifies list1 in place and returns None

print(list1)

# Output: [11, 21, 19, 4, 5, 6]

The return value of the extend() method is None because it extends an existing list. In our case, we added three elements of list2 at the end of list1 and printed list1.

Method 3: Using itertools.chain()

What if you are working with massive lists (datasets) and you want to merge those efficiently? That’s where the itertools built-in package comes into the picture.

To efficiently merge two large lists in Python, use the itertools.chain() method to combine them.

The itertools.chain() method returns an iterator, and we need to convert back to a list using the list() constructor.

import itertools

list1 = range(100000) # Large list
list2 = range(100000) # Large list

merged_iterator = itertools.chain(list1, list2)

merged_list = list(merged_iterator)

print(merged_list)

# Output: [0, 1, 2, ..., 99999, 0, 1, 2, ..., 99999]

That’s all!

Post Views: 5
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Check If a Given Object is a List in Python
How to Print All Common Elements of Two Lists in Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend