# Combine two lists in Python

In this tutorial, we will see how to combine twolist in python

There are multiple ways to combine list in python.

## Using + operator

You can use `+ operator` to combine list in python.

Let’s understand with the help of example.

``` list1=[1,2,3,4] list2=[5,6,7,8] combinedList = list1 + list2 print("Combined List:",combinedList) ```

Output:

Combined List: [1, 2, 3, 4, 5, 6, 7, 8]

As you can see combined list has joined list1 and list2

## Using itertools.chain

Let’s understand with the help of example.

``` import itertools list1=[10,20,30,40] list2=[50,60,70,80] for i in itertools.chain(list1,list2): print(i) ```

Output:

10
20
30
40
50
60
70
80

There are two advantages of using this approach.

• You don’t have to create copy of list to iterate over elements
• You can combine other iterables such as set and tuple as well

There is another way to combine two lists in python>=3.5 version.Additional Unpacking Generalizations reduces synthetic sugar with * operator but it may not be very easy to understand. This approach is bit faster than other two.

``` list1=[10,20,30,40] list2=[50,60,70,80] combinedList=[*list1,*list2] print("Combind list:",combinedList) ```

Output:

Combind list: [10, 20, 30, 40, 50, 60, 70, 80]

## Remove duplicates in combined list

In case you want to remove duplicates in combined list, you can use + operator and then convert it to set and back to list.

``` list1=[10,20,30,40] list2=[50,10,20,60] combinedList=list(set(list1 + list2)) print("Combind list without duplicates:",combinedList) ```

Output:

Combind list without duplicates: [40, 10, 50, 20, 60, 30]

That’s all about how to combine two lists in python

## Related Posts

• 21 December

### Matrix multiplication in Python using user input

Learn about how to Matrix multiplication in Python using user input.

• 18 November

### How to print Array in Python

In this post, we will see how to print array in Python. As we know that, Python didn’t have an in-built array data type, so we try to use list data type as an array. We can also use the NumPy module for creating NumPy array and apply array operation on it. Now, we will […]

• 21 April

### Remove first element from list in Python

In this post, we will see how to remove the first element from a list in python. Using list.pop() We can use list.pop() method to remove the first element from the list. Output: List Of Fruits are: [‘Orange’, ‘Apple’, ‘Grapes’, ‘Mango’] List Of Fruits after removing first element: [‘Apple’, ‘Grapes’, ‘Mango’] Removed Fruit: Orange pop […]

• 26 March

### Find average of list in Python

There are multiple ways to find the average of the list in Python. Using sum() and len() We can use sum() to find sum of list and then divide it with len() to find average of list in Python. Here is the quick example of the same. [crayon-600d634d30551022834504/] Output: Average of listOfIntegers: 3.0 Using reduce(), […]

• 22 December

### Python list of lists

In this post, we will see how to create a list of lists in python. It is quite easy to create list of lists in Python. You just need to use list’s append method to create list of lists. Here is simple example to create list of lists in Python. Output: List of Lists: [[1, […]

• 21 December

### Python count items in the list

In this tutorial, we will see how to count items in

## Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.