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
- Function Definition: The
remove_duplicates
function takes a list as input and returns a new list with duplicate elements removed. - 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
- 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.