๐Ÿ
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

remove_duplicates

โ† All Python Programs

Aim:

☛   Write a function called remove_duplicates that takes a list and returns a new list with only the unique elements from the original. Hint: they don't have to be in the same order.

Solution :


PROGRAM: (remove_duplicates.py)

 
def remove_duplicates(my_list):
	for k in my_list :
		if my_list . count(k) > 1 :
			del my_list[my_list.index(k)]
user_list = input(" Please enter a list : ").split()
print(" Your list : " , user_list)
remove_duplicates(user_list)
print(" Your list without duplicates : \n " , user_list)

OUTPUT:

 
Please enter a list : 6 7 2 3 1 3 1 8 6
Your list : [ '6' , '7' , '2' , '3' , '1' , '3' , '1' , '8' , '6' ]
Your list without duplicates :
[ '7' , '2' , '3' , '1' , '8' , '6' ]



๐Ÿ’ป Run This Python Program

remove_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