Issue
from collections import Counter
selected_element = 3
arr = [1,2,3,4,3,5,5]
def duplicates(values):
dups = Counter(values) - Counter(set(values))
return list(dups.keys())
print(duplicates(arr))
output: [3, 5]
I want only the selected element to be displayed which is '3' how would I do that?
Solution
You can easily use count :
selected_element = 3
arr = [1,2,3,4,3,5,5]
print(arr.count(selected_element)>1)
count of selected element should be greater than 1 if it has any duplicates.
Answered By - Nilanka Manoj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.