About 448,000 results
Open links in new tab
  1. How to Find Duplicates in a ListPython | GeeksforGeeks

    Nov 27, 2024 · Removing duplicates from a list is a common operation in Python which is useful in scenarios where unique elements are required. Python provides multiple methods to achieve this. Using set() method is most efficient for unordered lists.

  2. Identify duplicate values in a list in Python - Stack Overflow

    That's the simplest way I can think for finding duplicates in a list: my_list = [3, 5, 2, 1, 4, 4, 1] my_list.sort() for i in range(0,len(my_list)-1): if my_list[i] == my_list[i+1]: print str(my_list[i]) + ' is a duplicate'

  3. python - How do I find the duplicates in a list and create another list

    use of list.count() method in the list to find out the duplicate elements of a given list. arr=[] dup =[] for i in range(int(input("Enter range of list: "))): arr.append(int(input("Enter Element in a list: "))) for i in arr: if arr.count(i)>1 and i not in dup: dup.append(i) print(dup)

  4. Program to print duplicates from a list of integers in Python

    Dec 27, 2024 · In this article, we will explore various methods to print duplicates from a list of integers in Python. The simplest way to do is by using a set. Using Set. Set in Python only stores unique elements. So, we loop through the list and check if the current element already exist (duplicate) in the set, if true then

  5. python - Efficiently finding duplicates in a list - Stack Overflow

    Oct 4, 2017 · You can optimise this a bit using a yield statement, and return duplicates as you find them. def get_duplicates(array): c = Counter() seen = set() for i in array: c[i] += 1 if c[i] > 1 and i not in seen: seen.add(i) yield i

  6. Find Duplicates in a Python List - datagy

    Dec 16, 2021 · How to Find Duplicates in a List in Python. Let’s start this tutorial by covering off how to find duplicates in a list in Python. We can do this by making use of both the set() function and the list.count() method. The .count() method takes a single argument, the item you want to count, and returns the number of times that item appears in a ...

  7. Python Find Duplicates in List - Know Program

    In Python, there are many methods available on the list data type that help you find duplicates elements from a given list. In this post, we are using set (), count (), list comprehension, enumerate (), slicing + in operator, and Brute Force approach.

  8. 5 Best Ways to Find Duplicate Items in a List in Python

    Mar 3, 2024 · 💡 Problem Formulation: When working with lists in Python, a common task is to identify duplicate items. For example, given a list ['apple', 'banana', 'cherry', 'apple', 'cherry'], the goal is to detect the duplicates, yielding an output like ['apple', 'cherry']. This article explores various methods to find these duplicates efficiently.

  9. Finding Duplicates in a List in Python - CodeRivers

    Apr 9, 2025 · To find duplicates, we need to compare each element in the list with every other element or use data structures and algorithms that can efficiently identify repeated values. The most straightforward way to find duplicates in a list is by using nested loops.

  10. Python – Duplicate Element Indices in List - GeeksforGeeks

    Feb 1, 2025 · We use list comprehension to create a dictionary where each duplicate element maps to a list of its indices filtering elements that appear more than once. This is achieved by iterating over unique elements and using enumerate() to collect indices of duplicates.

Refresh