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.
Answers
Explanation:
Find the two repeating elements in a given array
You are given an array of n+2 elements. All elements of the array are in range 1 to n. And all elements occur once except two numbers which occur twice. Find the two repeating numbers.
For example, array = {4, 2, 4, 5, 2, 3, 1} and n = 5
The above array has n + 2 = 7 elements with all elements occurring once except 2 and 4 which occur twice. So the output should be 4 2.
Answer:
# Program in python for giving output as distinct elements
# function to delete duplicate entries
def deleteDup(list1):
length = len(list1) #Checking the length of list for 'for' loop
newList = [] #Defining a new list for adding unique elements
for a in range(length):
#Checking if an element is not in the new List
#This will reject duplicate values
if list1[a] not in newList:
newList.append(list1[a])
return newList
# empty list for taking the elements in list
list1 = []
# number of elements in the list
inp = int(input(" Enter number of elements : "))
#Taking the input from the user
for i in range(inp):
a = int(input("Enter the elements of the list: "))
list1.append(a)
#Printing the list
print("The list entered is:",list1)
# list without duplicate elements
print("The list without duplicate elements is:", deleteDup(list1))
OUTPUT:
Enter the number of elements 6
Enter the elements of the list: 12
Enter the elements of the list: 14
Enter the elements of the list: 12
Enter the elements of the list: 12
Enter the elements of the list: 31
Enter the elements of the list: 14
The list entered is: [12, 14, 12, 12, 31, 14]
The list without duplicate elements is: [12, 14, 31]
To learn more about python, click on the link below:
https://brainly.in/question/16086632
To learn more about the functions of python, click on the link below:
https://brainly.in/question/47644111
#SPJ3