Informatics Practices
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.
Answer
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]
Related Questions
Write a program to find the largest and the second largest elements in a given list of elements.
Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are arranged in order. If there are two middle values, then take their average.
Hint: Use an inbuilt function to sort the list.
Write a program to create a list of elements. Input an element from the user that has to be inserted in the list. Also, input the position at which it is to be inserted.
Write a program to read elements of a list and do the following:
(a) The program should ask for the position of the element to be deleted from the list and delete the element at the desired position in the list.
(b) The program should ask for the value of the element to be deleted from the list and delete this value from the list.