---
title: "Write a function to remove duplicate elements from a list in python."  
description: "Write a function to remove duplicate elements from a list in python."  
author: "Steilla Mitchel"  
published: 2023-06-18  
updated: 2023-06-19  
canonical: https://www.mindstick.com/forum/158773/write-a-function-to-remove-duplicate-elements-from-a-list-in-python  
category: "python"  
tags: ["python", "programs"]  
reading_time: 2 minutes  

---

# Write a function to remove duplicate elements from a list in python.

Write a [function to remove duplicate](https://www.mindstick.com/forum/158810/write-a-function-to-remove-duplicate-elements-from-a-vector-in-rust) [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) from a list.

## Replies

### Reply by Aryan Kumar

Sure, here is a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) to [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:

Python

```plaintext
def remove_duplicates(list1):
  """
  Removes duplicate elements from a list.

  Args:
    list1: The list to remove duplicates from.

  Returns:
    A new list without duplicates.
  """

  new_list = []
  for item in list1:
    if item not in new_list:
      new_list.append(item)

  return new_list

if __name__ == "__main__":
  list1 = [1, 2, 3, 4, 5, 1, 2, 3]
  new_list = remove_duplicates(list1)
  print(new_list)
```

This function takes a list as input and returns a new list without any duplicates. The function works by first creating a new empty list. Then, it iterates through the original list and adds each item to the new list if it is not already in the new list. Finally, the function returns the new list.

To run the function, you can save it as a Python file and then run it from the command line. For example, if you save the function as remove_duplicates.py, you can run it by typing the following command into the command line:

Code snippet

```plaintext
python remove_duplicates.py
```

This will print the new list without any duplicates to the console.

Here is an example of the output of the function:

Code snippet

```plaintext
[1, 2, 3, 4, 5]
```

As you can see, the output of the function is a list without any duplicates.


---

Original Source: https://www.mindstick.com/forum/158773/write-a-function-to-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.
