FIND THE DUPLICATE ELEMENT IN THE LIST IN PYTHON

from collections import Counter

numbers = [1, 2, 3, 1, 2, 4, 5]
duplicates = [item for item, count in Counter(numbers).items() if count > 1]
print(duplicates)  # Output: [1, 2]
Python

Leave a Reply

Your email address will not be published. Required fields are marked *


error: Content is protected !!
Scroll to Top
MacroNepal
Verified by MonsterInsights