---
title: "Find duplicate elements in a list"  
description: "Find duplicate elements in a list"  
author: "ICSM Computer"  
published: 2025-09-10  
updated: 2025-09-10  
canonical: https://www.mindstick.com/interview/34370/find-duplicate-elements-in-a-list  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 2 minutes  

---

# Find duplicate elements in a list

## Using Counter :

```python
from collections import Counter

nums = [1, 2, 3, 2, 4, 5, 1, 6, 3]

counts = Counter(nums)
duplicates = [item for item, count in counts.items() if count > 1]

print("Duplicates:", duplicates)
```

## Output:

```plaintext
Duplicates: [1, 2, 3]
```

## Using Set :

```python
def find_duplicates(nums):
    seen = set()
    duplicates = set()
    for n in nums:
        if n in seen:
            duplicates.add(n)
        else:
            seen.add(n)
    return list(duplicates)

print(find_duplicates([1, 2, 3, 2, 4, 5, 1, 6, 3]))
```

**Answer:** (order may vary)

```plaintext
[1, 2, 3]
```

## Explanation:

- Keep track of numbers in `seen`.
- If already in `seen`, move to `duplicates`.

## Read More:

- [**Write code to Word Palindrome check**](https://www.mindstick.com/interview/34369/write-code-to-word-palindrome-check)
- [**Factorial of a number using loop**](https://www.mindstick.com/forum/161907/factorial-of-a-number-using-loop)
- [**Check if a number is Prime**](https://www.mindstick.com/forum/161906/check-if-a-number-is-prime)
- [**Reverse a string without using slicing in python**](https://www.mindstick.com/forum/161902/reverse-a-string-without-using-slicing-in-python)

## Answers

### Answer by ICSM Computer

## Using Counter :

```python
from collections import Counter

nums = [1, 2, 3, 2, 4, 5, 1, 6, 3]

counts = Counter(nums)
duplicates = [item for item, count in counts.items() if count > 1]

print("Duplicates:", duplicates)
```

## Output:

```plaintext
Duplicates: [1, 2, 3]
```

## Using Set :

```python
def find_duplicates(nums):
    seen = set()
    duplicates = set()
    for n in nums:
        if n in seen:
            duplicates.add(n)
        else:
            seen.add(n)
    return list(duplicates)

print(find_duplicates([1, 2, 3, 2, 4, 5, 1, 6, 3]))
```

**Answer:** (order may vary)

```plaintext
[1, 2, 3]
```

## Explanation:

- Keep track of numbers in `seen`.
- If already in `seen`, move to `duplicates`.

## Read More:

- [**Write code to Word Palindrome check**](https://www.mindstick.com/interview/34369/write-code-to-word-palindrome-check)
- [**Factorial of a number using loop**](https://www.mindstick.com/forum/161907/factorial-of-a-number-using-loop)
- [**Check if a number is Prime**](https://www.mindstick.com/forum/161906/check-if-a-number-is-prime)
- [**Reverse a string without using slicing in python**](https://www.mindstick.com/forum/161902/reverse-a-string-without-using-slicing-in-python)


---

Original Source: https://www.mindstick.com/interview/34370/find-duplicate-elements-in-a-list

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
