Python function program to get unique values from the given list

In this python function program, we will create a function to get unique values from the given 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 a set to get the unique value using set().
  5. Convert the set into a list using list()
  6. Print the output.
  7. Pass the list to the function while calling the function.
				
					def unique(l):
    distinct = set(l)
    print(list(distinct))
unique([4, 6, 1, 7, 6, 1, 5])
				
			

Output :

				
					[1, 4, 5, 6, 7]
				
			

Related Articles

check whether a combination of two numbers has a sum of 10 from the given list.

get the duplicate characters from the string.

Leave a Comment