duplicates

Django: Filtering on the related object, removing duplicates from the result

≯℡__Kan透↙ 提交于 2019-12-03 12:45:39
Given the following models: class Blog(models.Model): name = models.CharField() class Entry(models.Model): blog = models.ForeignKey(Blog) content = models.CharField() I am looking to pass the following to a template: blogs = Blog.objects.filter(entry__content__contains = 'foo') result = [(blog, blog.entry_set.filter(content__contains = 'foo')) for blog in blogs] render_to_response('my.tmpl', {'result': result} However, "Blog.objects.filter(...)" returns the same Blog object multiple times if more than one matching entry is found. How do you remove the duplicates? Or better yet, am I missing a

Determine when columns of a data.frame change value and return indices of the change

喜夏-厌秋 提交于 2019-12-03 12:13:00
问题 I am trying to find a way to determine when a set of columns changes value in a data.frame. Let me get straight to the point, please consider the following example: x<-data.frame(cnt=1:10, code=rep('ELEMENT 1',10), val0=rep(5,10), val1=rep(6,10),val2=rep(3,10)) x[4,]$val0=6 The cnt column is a unique ID (could be a date, or time column, for simplicity it's an int here) The code column is like an code for the set of rows (imagine several such groups but with different codes). The code and cnt

Remove first occurrence of elements in a vector from another vector

拥有回忆 提交于 2019-12-03 10:44:38
I have a character vector, including some elements that are duplicates e.g. v <- c("d09", "d11", "d13", "d01", "d02", "d10", "d13") And another vector that includes single counts of those characters e.g. x <- c("d10", "d11", "d13") I want to remove only the first occurrence of each element in x from the 2nd vector v . In this example, d13 occurs in x and twice in v , but only the first match is removed from v and the duplicate is kept. Thus, I want to end up with: "d09", "d01", "d02", "d13" I've been trying various things e.g. z <- v[!(v %in% x)] but it keeps removing all instances of the

Remove duplicates from array comparing the properties of its objects

北战南征 提交于 2019-12-03 09:38:48
问题 Suppose I have a class Event, and it has 2 properties: action (NSString) and date (NSDate). And suppose I have an array of Event objects. The problem is that "date" properties can match. I need to remove the duplicates, meaning that 2 different objects with the same date IS a duplicate. I can remove duplicates in any array of strings or nsdates, they are easy to compare. But how to do it with complex objects, where their properties are to be compared? Don't ask me what I did so far, cos' the

How do I create a multiple column unique constraint in SQL Server

半世苍凉 提交于 2019-12-03 09:36:43
问题 I have a table that contains, for example, two fields that I want to make unique within the database. For example: create table Subscriber ( ID int not null, DataSetId int not null, Email nvarchar(100) not null, ... ) The ID column is the primary key and both DataSetId and Email are indexed. What I want to be able to do is prevent the same Email and DataSetId combination appearing in the table or, to put it another way, the Email value must be unique for a given DataSetId. I tried creating a

strategies for finding duplicate mailing addresses

落花浮王杯 提交于 2019-12-03 08:17:45
I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses: addr_1 = '# 3 FAIRMONT LINK SOUTH' addr_2 = '3 FAIRMONT LINK S' addr_3 = '5703 - 48TH AVE' adrr_4 = '5703- 48 AVENUE' I'm planning on applying some string transformation to make long words abbreviated, like NORTH -> N, remove all spaces, commas and dashes and pound symbols. Now, having this output, how can I compare addr_3 with the rest of addresses and detect similar? What percentage of similarity would be safe? Could you provide a simple python code for this?

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

本秂侑毒 提交于 2019-12-03 07:46:08
问题 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. 回答1: This is how I would do it. EDIT: I wrote this into a more generalized utility

Extract duplicate objects from a List in Java 8

天大地大妈咪最大 提交于 2019-12-03 07:31:46
This code removes duplicates from the original list, but I want to extract the duplicates from the original list -> not removing them (this package name is just part of another project): Given: a Person pojo: package at.mavila.learn.kafka.kafkaexercises; import org.apache.commons.lang3.builder.ToStringBuilder; public class Person { private final Long id; private final String firstName; private final String secondName; private Person(final Builder builder) { this.id = builder.id; this.firstName = builder.firstName; this.secondName = builder.secondName; } public Long getId() { return id; }

Find possible duplicates in two columns ignoring case and special characters

安稳与你 提交于 2019-12-03 07:19:00
Query SELECT COUNT(*), name, number FROM tbl GROUP BY name, number HAVING COUNT(*) > 1 It sometimes fails to find duplicates between lower case and upper case. E.g.: sunny and Sunny don't show up as a duplicates. So how to find all possible duplicates in PostgreSQL for two columns. Erwin Brandstetter lower() / upper() Use one of these to fold characters to either lower or upper case. Special characters are not affected: SELECT count(*), lower(name), number FROM tbl GROUP BY lower(name), number HAVING count(*) > 1; unaccent() If you actually want to ignore diacritic signs, like your comments

How can I remove duplicate nodes in XQuery?

随声附和 提交于 2019-12-03 07:08:37
问题 I have an XML document I generate on the fly, and I need a function to eliminate any duplicate nodes from it. My function looks like: declare function local:start2() { let $data := local:scan_books() return <books>{$data}</books> }; Sample output is: <books> <book> <title>XML in 24 hours</title> <author>Some Guy</author> </book> <book> <title>XML in 24 hours</title> <author>Some Guy</author> </book> </books> I want just the one entry in my books root tag, and there are other tags, like say