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
- Create a function unique.
- Use the def keyword to define the function.
- Pass a parameter i.e. list to the function.
- Convert the list to a set to get the unique value using set().
- Convert the set into a list using list()
- Print the output.
- 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
Python function program to get the duplicate characters from the string.
Python function program to get the square of all values in the given dictionary.
Python function program to create dictionary output from the given string.
Python function program to print a list of prime numbers from 1 to 100.
Python function program to get a list of odd numbers from 1 to 100.
Python function program to print and accept login credentials.