Computer Science, asked by bhakatbinita44, 7 months ago

Write a program using function to input a list of elements and display a list with only

duplicate elements after removing the unique ones.

Output :

The original list : [10, 20, 30, 10, 40, 20, 50]

The unique list : [10, 20]​

Answers

Answered by gupukaur1503
0

Explanation:

Given a list of integers with duplicate elements in it. The task to generate another list, which contains only the duplicate elements. In simple words, the new list should contain the elements which appear more than one.

Examples :

Input : list = [10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]

Output : output_list = [20, 30, -20, 60]

Input : list = [-1, 1, -1, 8]

Output : output_list = [-1]

Below is the implementation :

# Python program to print

# duplicates from a list

# of integers

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

# Driver Code

list1 = [10, 20, 30, 20, 20, 30, 40,

50, -20, 60, 60, -20, -20]

print (Repeat(list1))

# This code is contributed

# by Sandeep_anand

Output :

[20, 30, -20, 60]

Answered by parry8016
1

Explanation:

HERE IS U R ANSWER DEAR PLZ FOLLW ME

Attachments:
Similar questions