written 23 months ago by
pedsangini276
• 4.7k
|
•
modified 23 months ago
|
Explanation:-
- Create a variable n which stores the no of elements user wants to add to the list.
- Iterate for loop n times and take the elements entered from the user and append them to a list l & pass on this list l to function unique.
- This function has Initialized an empty list x.
- Iterate over all the elements in the list l check if that element is present in list x if not then append else move on to next element.
Code:-
def unique(l):
x=[]
for a in l:
if a not in x:
x.append(a)
return(x)
l=[]
n=int(input("enter the no of elements:-"))
for i in range(n):
print("enter element:-")
l.append(int(input()))
print("The elements the list:-",l)
print("Unique Elements in the list:-",unique(l))
Output