Questions tagged [duplicates]

The "duplicates" tag concerns detecting and/or dealing with multiple instances of items in collections.

A duplicate is any re-occurrence of an item in a collection. This can be as simple as two identical strings in a list of strings, or multiple complex objects which are treated as the same object when compared to each other.

This tag may pertain to questions about preventing, detecting, removing, or otherwise dealing with unwanted duplicates, or adapting to safely allow duplicates.

15777 questions
23
votes
8 answers

Detect when multiple enum items map to same value

Is there a compile-time way to detect / prevent duplicate values within a C/C++ enumeration? The catch is that there are multiple items which are initialized to explicit values. Background: I've inherited some C code such as the following: #define…
Dan
  • 10,303
  • 5
  • 36
  • 53
23
votes
7 answers

Find and remove duplicate rows by two columns

I read all the relevant duplicated questions/answers and I found this to be the most relevant answer: INSERT IGNORE INTO temp(MAILING_ID,REPORT_ID) SELECT DISTINCT MAILING_ID,REPORT_IDFROM table_1 ; The problem is that I want to remove duplicates…
user838437
  • 1,451
  • 7
  • 23
  • 31
23
votes
10 answers

How to keep only one row of a table, removing duplicate rows?

I have a table that has a lot of duplicates in the Name column. I'd like to only keep one row for each. The following lists the duplicates, but I don't know how to delete the duplicates and just keep one: SELECT name FROM members GROUP BY name…
Gulbahar
  • 5,343
  • 20
  • 70
  • 93
23
votes
6 answers

How to search Array for multiple values in PHP?

I need to get the keys from values that are duplicates. I tried to use array_search and that worked fine, BUT I only got the first value as a hit. I need to get both keys from the duplicate values, in this case 0 and 2. The search result output as…
Jens Törnell
  • 23,180
  • 45
  • 124
  • 206
22
votes
10 answers

How to remove duplicate words from a plain text file using linux command

I have a plain text file with words, which are separated by comma, for example: word1, word2, word3, word2, word4, word5, word 3, word6, word7, word3 i want to delete the duplicates and to become: word1, word2, word3, word4, word5, word6,…
cupakob
  • 8,411
  • 24
  • 67
  • 76
22
votes
6 answers

Removing duplicate columns and rows from a NumPy 2D array

I'm using a 2D shape array to store pairs of longitudes+latitudes. At one point, I have to merge two of these 2D arrays, and then remove any duplicated entry. I've been searching for a function similar to numpy.unique, but I've had no luck. Any…
Sergi
  • 454
  • 1
  • 4
  • 21
22
votes
8 answers

Select one row without duplicate entries

In mysql table info i have : Id , Name , City , date , status I want to select all names from "info" Making the query $query = mysql_query("SELECT name FROM info WHERE status = 1 ORDER BY id") or die(mysql_error()); while ($raw =…
Darius
  • 253
  • 1
  • 2
  • 9
22
votes
4 answers

How do you get the duplicate key that ToDictionary() has failed on?

I'm creating a Dictionary object, using IEnumerable's ToDictionary() extension method: var dictionary = new Dictionary (myCollection.ToDictionary(k => k.Key)); When it executes, it throws the following…
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
22
votes
6 answers

Avoiding duplicated messages on JMS/ActiveMQ

Is there a way to suppress duplicated messages on a queue defined on ActiveMQ server? I tried to define manually JMSMessageID, (message.setJMSMessageID("uniqueid")), but server ignores this modification and deliver a message with built-in generated…
Andre Pastore
  • 2,841
  • 4
  • 33
  • 44
22
votes
7 answers

Check std::vector has duplicates

I want to check if a vector of integers has any duplicates or not, and have to return true if it does. So I try to do something like this: vector uGuess = {1,2,3,3,4,5} vector a = uGuess; sort(a.begin(), a.end()); bool d =…
rrc
  • 275
  • 1
  • 3
  • 7
22
votes
3 answers

Word-oriented completion suggester (ElasticSearch 5.x)

ElasticSearch 5.x introduced some (breaking) changes to the Suggester API (Documentation). Most notable change is the following: Completion suggester is document-oriented Suggestions are aware of the document they belong to. Now, associated…
alesc
  • 2,776
  • 3
  • 27
  • 45
22
votes
3 answers

Is a python dict comprehension always "last wins" if there are duplicate keys

If I create a python dictionary with a dict comprehension, but there are duplicate keys, am I guaranteed that the last item will be the one that ends up in the final dictionary? It's not clear to me from looking at…
user2667066
  • 1,867
  • 2
  • 19
  • 30
22
votes
3 answers

coloring cells in excel with pandas

I need some help here. So i have something like this import pandas as pd path = '/Users/arronteb/Desktop/excel/ejemplo.xlsx' xlsx = pd.ExcelFile(path) df = pd.read_excel(xlsx,'Sheet1') df['is_duplicated'] = df.duplicated('#CSR') df_nodup =…
22
votes
12 answers

Remove duplicates in an array without changing order of elements

I have an array, say List 139, 127, 127, 139, 130 How to remove duplicates of it and keep its order unchanged? i.e. 139, 127, 130
Deqing
  • 14,098
  • 15
  • 84
  • 131
22
votes
8 answers

How to find duplicate filenames (recursively) in a given directory? BASH

I need to find every duplicate filenames in a given dir tree. I dont know, what dir tree user will give as a script argument, so I dont know the directory hierarchy. I tried this: #!/bin/sh find -type f | while IFS= read vo do echo `basename…
yak
  • 3,770
  • 19
  • 60
  • 111