Write a program to find all duplicates in a list. [CBSE Text Book]
Answers
Answered by
0
Answer:
Explanation:
def Repeat(x):
_size = len(x)
repeated = []
for i in range(_size):
k = i + 1
for j in range(k, _size):
if x[i] == x[j] and x[i] not in repeated:
repeated.append(x[i])
return repeated
list1 = [10, 20, 30, 20, 20, 30, 40,
50, -20, 60, 60, -20, -20]
print (Repeat(list1))
Answered by
0
The program in python language is as follows:
X = [ a , b , c , b , a , e , f , e , e , e ]
import collections // It is a High-performance container datatype
print ( [ ele for ele , count in collections . Counter(X) . items( ) if count > 1 ] )
- In the above program, collection module is used which provides alternatives to general purpose built-in containers in Python i.e. dict, list, set, and tuple.
- The above program will print all the duplicates in the given list.
Similar questions