Program to take a list and returns a new list with unique elements of the first list

In this python function program, we will take a list and returns a new list with unique elements of the first list.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function unique
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. list to the function.
  4. Convert the list to set using set() to remove the duplicate values.
  5. Now convert it back to the list using list().
    Print the output.
  6. Create a list and pass that list to the function while calling the function.
				
					def unique(list1):
    print(list(set(list1)))
    
l = [2, 2, 3, 1, 4, 4, 4, 4, 4, 6]
unique(l)
				
			

Output :

				
					[1, 2, 3, 4, 6]
				
			

Related Articles

check whether a number is in a given range.

take a number as a parameter and checks whether the number is prime or not.

Leave a Comment