Q. Implement the following function for a linear list, which find outs and returns the number of unique elements in the list
def unique(lst):
"""passed parameter 1st is a list of integers (could be empty). """
After implementing the above function, test it with following lists and show the output produced by above function along with the reason for that output.
(i) Ist [ ]
(ii) Ist = [1, 2, 3]
(iii) Ist = [1, 2, 2]
(iv) Ist = [1, 2, 2, 3, 3]
Answer =
def unique(lst): for i in lst : if lst.count( i ) > 1 : while i in lst : lst.remove( i ) return len(lst) lst = eval(input("Enter a list :-")) print("Number of unique element = ",unique(lst) )
Where is the output?
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )