๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

has_duplicates

โ† All Python Programs

Aim:

☛   Write a function called has_duplicates that takes a list and returns True if there is any element that appears more than once. It should not modify the original list.

Solution :


PROGRAM: (has_duplicates.py)

 
def has_duplicate(my_list):
	for k in my_list:
		if my_list.count(k) > 1 :
			return True
			break
		else :
			return False
user_list = input(" Please enter a list : ").split()
print(" Your list : " , user_list)
res = has_duplicate ( user_list )
if res :
	print( " The list contain duplicate values ")
else :
	print( " The list not contain duplicate values ")

OUTPUT:

 
Sample Output 1:
Please enter a list : 6 7 2 3 1 3 1 8 6
Your list : [ '6' , '7' , '2' , '3' , '1' , '3' , '1' , '8' , '6' ]
The list contain duplicate values

Sample Output 2:
Please enter a list : 6 7 2 3 1 8 9
Your list : [ '6' , '7' , '2' , '3' , '1' , '8' , '9' ]
The list not contain duplicate values



๐Ÿ’ป Run This Python Program

has_duplicates
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals