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
- 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 set using set() to remove the duplicate values.
- Now convert it back to the list using list().
Print the output. - 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]