---
title: "How do you remove duplicate elements from a list in Python?"  
description: "How do you remove duplicate elements from a list in Python?"  
author: "Utpal Vishwas"  
published: 2023-06-26  
updated: 2023-06-27  
canonical: https://www.mindstick.com/forum/158874/how-do-you-remove-duplicate-elements-from-a-list-in-python  
category: "python"  
tags: ["python", "list"]  
reading_time: 2 minutes  

---

# How do you remove duplicate elements from a list in Python?

How do you [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) [duplicate elements](https://www.mindstick.com/forum/158954/how-to-remove-duplicate-elements-from-a-list-in-python) from a list in [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?

## Replies

### Reply by Aryan Kumar

There are several ways to remove duplicates from a list in Python. Here are some of the most common methods:

**Using the** `set()` **method**

The `set()` method creates a new set from the [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) of a list. Sets do not allow [duplicate](https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server) elements, so the new set will only contain the unique elements from the original list. To use this method, you would simply pass the list to the `set()` method and then convert the resulting set back to a list.

Python

```plaintext
def remove_duplicates_set(list1):
    unique_list = set(list1)
    unique_list = list(unique_list)
    return unique_list

list1 = [1, 2, 3, 4, 5, 1, 2, 3]
unique_list = remove_duplicates_set(list1)
print(unique_list)
```

## Using list comprehension

You can also use list comprehension to remove duplicates from a list. List comprehension is a concise way to create a new list from an existing list. To use list comprehension to remove duplicates, you would simply iterate through the original list and add each element to the new list only if it is not already in the new list.

Python

```plaintext
def remove_duplicates_list_comprehension(list1):
    unique_list = []
    for item in list1:
        if item not in unique_list:
            unique_list.append(item)
    return unique_list

list1 = [1, 2, 3, 4, 5, 1, 2, 3]
unique_list = remove_duplicates_list_comprehension(list1)
print(unique_list)
```

**Using the** `in` **and** `not in` **operators**

You can also use the `in` and `not in` operators to remove duplicates from a list. The `in` operator checks whether an element is in a list, and the `not in` operator checks whether an element is not in a list. To use these operators to remove duplicates, you would simply iterate through the original list and add each element to the new list only if it is not already in the new list.

Python

```plaintext
def remove_duplicates_in_not_in(list1):
    unique_list = []
    for item in list1:
        if item not in unique_list:
            unique_list.append(item)
    return unique_list

list1 = [1, 2, 3, 4, 5, 1, 2, 3]
unique_list = remove_duplicates_in_not_in(list1)
print(unique_list)
```

These are just a few of the ways to remove duplicates from a list in Python. The best method to use will depend on the specific situation.


---

Original Source: https://www.mindstick.com/forum/158874/how-do-you-remove-duplicate-elements-from-a-list-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
