CBSE Class 11 Informatics Practices Question 58 of 80

Lists in Python — Question 21

Back to all questions
21
Question

Question 16

Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements, i.e., all elements occurring multiple times in the list should appear only once.

Solution
nums = eval(input("Enter list: "))

unique_nums = []
for num in nums:
    if num not in unique_nums:
        unique_nums.append(num)

print("The list without duplicates is: ", unique_nums)
Output
Enter list: [11, 34, 67, 8, 66, 11, 8, 5]
The list without duplicates is:  [11, 34, 67, 8, 66, 5]

Answer