Important Notice:

Find Duplicate Elements in a List

Find Duplicate Elements in a List

16 views 1 min read
Program 13: Find Duplicate Elements in a List
 
हिंदी में: Duplicate Elements वे elements होते हैं जो List में एक से अधिक बार आते हैं।
English: Duplicate elements are values that occur more than once in a list.
 
Code:

numbers = [10, 20, 30, 20, 40, 10, 50, 10]

duplicates = []

for num in numbers:
    if numbers.count(num) > 1 and num not in duplicates:
        duplicates.append(num)

print("Duplicate Elements:", duplicates)
Output:
 
Duplicate Elements: [10, 20]
 
Explanation: count() किसी element की occurrences गिनता है। num not in duplicates यह सुनिश्चित करता है कि प्रत्येक duplicate केवल एक बार result में आए।

Related Notes