Informatics Practices
WAP in Python to delete all duplicate elements in a list.
For example,
If list is: [5, 2, 4, -5, 12, 2, 7, 4]
After deleting duplicate elements, new list should be: [5, 2, 4, -5, 12, 7]
Python List Manipulation
5 Likes
Answer
nums = eval(input("Enter a list: "))
unique_nums = []
for num in nums:
if num not in unique_nums:
unique_nums.append(num)
print("The list after deleting duplicate elements is: ", unique_nums)
Output
Enter a list: [5, 2, 4, -5, 12, 2, 7, 4]
The list after deleting duplicate elements is: [5, 2, 4, -5, 12, 7]
Answered By
3 Likes
Related Questions
Write a program that accepts elements of a list S and adds all the odd values and displays the sum.
Write a program to calculate the mean of a given list of numbers.
Write a program to calculate the minimum element of a given list of numbers.
Write a code to calculate and display total marks and percentage of a student from a given list storing the marks of a student.