Python | Program for printing duplicates from a list of integers

Python Methods and Functions

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 print program
# duplicates from the list
number 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 < / code> , - 20 , - 20 ]

print (Repeat (list1))

 
# This code has been added
# by Sandeep_anand

Output:

 [20, 30, -20, 60 ] 




Get Solution for free from DataCamp guru