human
Can you provide a code to find duplicates in a given array when elements are not limited to a range and the other steps required given the following:
Find duplicates in a given array when elements are not limited to a range | Function to find the Duplicates , if duplicate occurs 2 times or more than 2 times in array so , it will print duplicate value only once at output.
Initialize ifPresent as false.
ArrayList to store the output.
Checking if element is present in the ArrayList or not if present then break.
If element is not present in the ArrayList then add it to ArrayList and make ifPresent at true.
If duplicates is present then print ArrayList.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to find duplicates in a given array when elements are not limited to a range and the other steps required.
 def findDuplicates ( arr , Len ) :
	ifPresent = False
	a1 = [ ]
	for i in range ( Len - 1 ) :
		for j in range ( i + 1 , Len ) :
			if ( arr [ i ] == arr [ j ] ) :
				if arr [ i ] in a1 :
					break
				else :
					a1 . append ( arr [ i ] )
					ifPresent = True
	if ( ifPresent ) :
		print ( a1 , end = " ▁ " )
	else :
		print ( " No ▁ duplicates ▁ present ▁ in ▁ arrays " )
arr = [ 12 , 11 , 40 , 12 , 5 , 6 , 5 , 12 , 11 ]
n = len ( arr )
findDuplicates ( arr , n )