duplicates

What is the most elegant way to find index of duplicate items in C# List

此生再无相见时 提交于 2019-11-30 03:53:04
问题 I've got a List<string> that contains duplicates and I need to find the indexes of each. What is the most elegant, efficient way other than looping through all the items. I'm on .NET 4.0 so LINQ is an option. I've done tons of searching and connect find anything. Sample data: var data = new List<string>{"fname", "lname", "home", "home", "company"}(); I need to get the indexes of "home". 回答1: You can create an object from each item containing it's index, then group on the value and filter out

Java LinkedList - differences between retrieve operations

一曲冷凌霜 提交于 2019-11-30 03:23:11
Are there any differences between different methods in each of the following groups of element retrieve operations in LinkedList ? Returning null + removing operations: poll() , pollFirst() . Returning null + not removing operations: peek() , peekFirst() . Throwing exception + removing operations: pop() , remove() , removeFirst() . Throwing exception + not removing operations: element() , getFirst() . Similar duplications exists in insertion methods. If there is no such difference, I would expect it to be mentioned in the javadoc of the methods (something like the good old "This is exactly

Python: Rename duplicates in list with progressive numbers without sorting list

点点圈 提交于 2019-11-30 03:04:28
Given a list like this: mylist = ["name", "state", "name", "city", "name", "zip", "zip"] I would like to rename the duplicates by appending a number to get the following result: mylist = ["name1", "state", "name2", "city", "name3", "zip1", "zip2"] I do not want to change the order of the original list. The solutions suggested for this related Stack Overflow question sorts the list, which I do not want to do. This is how I would do it. EDIT: I wrote this into a more generalized utility function since people seem to like this answer. mylist = ["name", "state", "name", "city", "name", "zip", "zip

MySQL List All Duplicates [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-30 01:08:03
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Find duplicate records in MySQL I have a table in MySQL like this: ID name email 1 john abc@abc.com 2 johnny abc@abc.com 3 jim eee@eee.com 4 Michael abec@awwbc.com How can I have the MySQL query that will list out the duplicate one like this? Result of duplicate search: ID name email Duplicate 1 john abc@abc.com 2 2 johnny abc@abc.com 2 回答1: SELECT a.*, b.totalCount AS Duplicate FROM tablename a INNER JOIN (

iOS extensions with multiple targets

馋奶兔 提交于 2019-11-29 23:40:08
In iOS 8, when we create a new extension, we have to decide which target it is attached to. The extension will have the same bundle ID's prefix as the target. Is there any way to change the target afterward? If my project contains 2 (or more) targets (for example one for debug/simulator, one for production/device), what's the best way to work with extensions? Do I need to create another extension and duplicate the code (very bothersome to keep the same code for both targets)? To share one widget among a lot of targets one should only add widget.appex target to Embedded Binaries for every

how to avoid duplicates in a has_many :through relationship?

拥有回忆 提交于 2019-11-29 22:57:00
How can I achieve the following? I have two models (blogs and readers) and a JOIN table that will allow me to have an N:M relationship between them: class Blog < ActiveRecord::Base has_many :blogs_readers, :dependent => :destroy has_many :readers, :through => :blogs_readers end class Reader < ActiveRecord::Base has_many :blogs_readers, :dependent => :destroy has_many :blogs, :through => :blogs_readers end class BlogsReaders < ActiveRecord::Base belongs_to :blog belongs_to :reader end What I want to do now, is add readers to different blogs. The condition, though, is that I can only add a

PHP: How to identify AND CHANGE duplicate values in an array?

為{幸葍}努か 提交于 2019-11-29 22:53:14
问题 OK, there are a lot of examples of duplicate detection and removal in php arrays, using array_unique() etc but what if you want to find dups, modify them, check again in a loop until all dups are now unique? I think it's something like using array_filter()... so as a more specific example, here's what would come out of a sql statement something like this: SELECT id, list.comboname FROM list INNER JOIN ( SELECT comboname FROM list GROUP BY comboname HAVING count(id) > 1 ) dup ON list.comboname

how to prevent adding duplicate keys to a javascript array

我怕爱的太早我们不能终老 提交于 2019-11-29 22:48:55
I found a lot of related questions with answers talking about for...in loops and using hasOwnProperty but nothing I do works properly. All I want to do is check whether or not a key exists in an array and if not, add it. I start with an empty array then add keys as the page is scrubbed with jQuery. Initially, I hoped that something simple like the following would work: (using generic names) if (!array[key]) array[key] = value; No go. Followed it up with: for (var in array) { if (!array.hasOwnProperty(var)) array[key] = value; } Also tried: if (array.hasOwnProperty(key) == false) array[key] =

SQLAlchemy: Modification of detached object

让人想犯罪 __ 提交于 2019-11-29 22:24:35
I want to duplicate a model instance (row) in SQLAlchemy using the orm. My first thought was to do this: i = session.query(Model) session.expunge(i) old_id = i.id i.id = None session.add(i) session.flush() print i.id #New ID However, apparently the detached object still "remembers" what id it had, even though I set the id to None while it was detached. Thus, session.flush() tries to execute an UPDATE changing the primary key to null. Is this expected behavior? How can I remove the 'memory' of this attribute, and just treat the detached object as a new object upon re-adding it to the session?

Fastest “Get Duplicates” SQL script

怎甘沉沦 提交于 2019-11-29 19:26:12
What is an example of a fast SQL to get duplicates in datasets with hundreds of thousands of records. I typically use something like: SELECT afield1, afield2 FROM afile a WHERE 1 < (SELECT count(afield1) FROM afile b WHERE a.afield1 = b.afield1); But this is quite slow. This is the more direct way: select afield1,count(afield1) from atable group by afield1 having count(afield1) > 1 You could try: select afield1, afield2 from afile a where afield1 in ( select afield1 from afile group by afield1 having count(*) > 1 ); Walter Mitty A similar question was asked last week. There are some good