Append One List to Another in Python Without Nesting

When I first started working with Python lists more than a decade ago, one of the most confusing things I faced was appending one list to another.

Over the years, I’ve learned multiple ways to append one list to another in Python without nesting. In this tutorial, I’ll walk you through these methods step by step.

I’ll also share some real-world examples that I’ve used in projects, especially when handling data for U.S.-based clients.

Ways to Append One List to Another in Python Without Nesting

Let me explain the scenario with one example so you can use the approach correctly.

These are two different lists,

list_1 = [1, 2, 3]
list_2 = [4, 5, 6]

Both lists have some data, so we need to append list_2 to list_1 without adding the brackets. Let’s understand all the methods and approaches one by one with practical examples and different scenarios.

Method 1: Use a for loop and append() Method

First, we will use the for loop and the append() method to merge two lists in Python. So, the for loop will individually target all the second list elements.

Syntax:

list_1.appned(list_2)
  • list_1.appned(element): This syntax is perfect for our requirement

Let’s combine the for loop and the append() method to merge two lists in Python.

today_sales = [2000, 4200,5000,6000,1500]
yesterday_sales = [1000, 3000, 4500, 6000, 1200]

for i in yesterday_sales:
    today_sales.append(i)

print("Total sales list: ", today_sales)

You can refer to the screenshot below to see the output.

Python Append List to List Without Nesting Using for loop and append() Method

I initialized a for loop to iterate ” i ” in the second list of elements like this:
for i in yesterday_sales:, I use the append() method to add an element into the first list like today_sales.append(i).

Method 2: Use a While Loop and the Insert() Method

We can also use the while loop and the insert() method to append a list into another in Python.

The while loop targets the index positions of all the elements individually, and the insert() method adds an element based on the given index position.

Syntax

list.insert(index_position, element)

Let’s understand how we can merge both the lists using the while loop and insert().

today_sale = [2000, 4200, 5000, 6000, 1500]
yesterday_sale = [1000, 3000, 4500, 6000, 1200]

i = 0
while i<len(yesterday_sale):
    today_sale.insert(len(today_sale), yesterday_sale[i])
    i+=1

print(today_sale)

You can refer to the screenshot below to see the output.

How to merge a list to another list in Python Using while loop and insert() Method

We’ve initialized i = 0 to target elements from the 0 index in the above code. Then, the while loop will iterate till len(yesterday_sale) like this: while i<len(yesterday_sale): Then, using the insert() method like this, today_sale.insert(len(today_sale), yesterday_sale[i]) to add an element at the end position of the list.

Method 3: Use extend() Method in Python

In Python, extend() is the direct way to merge two lists without including brackets. This is a preferable approach to use in this type of scenario.

Syntax

list_1.extend(list_2)
  • list_1.extend(list_2): Using the extend() method is more beneficial because it takes the list as a parameter, which means there is no need to iterate over single elements to merge the list.
east_states = ['New York', 'Florida', 'Georgia']
west_states = ['California', 'Washington', 'Nevada']

east_states.extend(west_states)
print(east_states)

You can refer to the screenshot below to see the output.

Append List to List Python Without Brackets Using extend() method

In the above code, we have two lists, east_states and west_states, and we need to merge both lists. So, we use the extend() method like this: east_states.extend(west_states).

Method 4: Use the (+=) Operator in Python

Performing concatenation in Python is also a direct way to merge two lists. Generally, we use the ( + ) operator for concatenation. But here, we are using the (+=) operator because we need to change the original list.

Syntax:

list_1 += list_2

Let’s understand how we can perform concatenation in Python to merge two lists without including the brackets.

east_states = ['New York', 'Florida', 'Georgia']
west_states = ['California', 'Washington', 'Nevada']
east_states += west_states
print(east_states)

You can refer to the screenshot below to see the output.

Merge two lists in Python by performing concatenation using (+=) operator

In the above code, we are using += to append west_states into the east_states like this: east_states += west_states

Conclusion

In this Python article, you learned how Python appends a list to another list without nesting in different ways and methods, such as using a for loop with the append() method, a while loop with the insert() method, an extend() method, and concatenation to merge two lists.

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.