Python Program to Remove Duplicates from a List

In this tutorial, we will discuss a Python program to remove duplicates from a list.

Related: Python Program to Count the Number of Words in a String

Program code to remove duplicates from a list in Python

# Remove Duplicates from a List in Python
def remove_duplicates(lst):
    return list(set(lst))

input_list = [1, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 9]
unique_list = remove_duplicates(input_list)
print("List after removing duplicates:", unique_list)

Explanation

  1. Function Definition: The remove_duplicates function takes a list as input and returns a new list with duplicate elements removed.
  2. Main Program: The program defines a list with duplicate elements and removes the duplicates using the remove_duplicates function. It then prints the list after removing duplicates.

Output

Python Program to Remove Duplicates from a List

  • When you run the above program, it will remove duplicates from the list and print the result.

Conclusion

  • In this tutorial, we learned how to remove duplicates from a list using a Python program.
  • Understanding this concept is essential for data manipulation and enhancing your programming skills.

You may also like...

Leave a Reply

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