Mid2 29th_List_Duplication_Checker
def has_duplicates(n, li):
for i in range(n):
for j in range(i + 1, n):
if li[i] == li[j]:
return True
return False
no = int(input("Enter how many numbers do you want in a list: "))
gl = []
for i in range(no):
x = int(input("Enter an element: "))
gl.append(x)
rst = has_duplicates(no, gl)
if rst:
print("The given list has duplicates")
else:
print("The given list does not have duplicates")
#output:
Enter how many numbers do you want in a list: 4
Enter an element: 1
Enter an element: 2
Enter an element: 3
Enter an element: 2
The given list has duplicates
Comments
Post a Comment