Questions tagged [unique]

Refers to an element that is distinctly different from any other element in a collection.

Refers to an element that is distinctly different from any other element in a collection.

6072 questions
51
votes
4 answers

Find index where elements change value numpy

Suppose I have >>> v array([1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 3, 4, 3, 4, 3, 4, 5, 5, 5]) Is there an efficient numpy way to find each index where the value changes? For instance, I would want some result like, >>> index_of_changed_values(v) [0, 5, 8,…
Aaron
  • 2,344
  • 3
  • 26
  • 32
50
votes
6 answers

JavaScript Unique Browser Id

is there anyway to create a unique ID for a browser within javascript? Im not talking about an ID that is random everytime it is generated but an ID that is unique to the browser it is generated in but also takes into account the computer its…
Ozzy
  • 10,285
  • 26
  • 94
  • 138
50
votes
10 answers

How can I make short random unique keys, like YouTube video IDs, in PHP?

Is there any way to create unique keys like those used in YouTube video urls (ex: https://www.youtube.com/watch?v=nWChTnkVdKE)?
kusanagi
  • 14,296
  • 20
  • 86
  • 111
50
votes
4 answers

Detecting a "unique" anonymous user

It is impossible to identify a user or request as unique since duping is trivial. However, there are a handful of methods that, combined, can hamper cheating attempts and give a user quasi-unique status. I know of the following: IP Address - store…
Omar
  • 39,496
  • 45
  • 145
  • 213
50
votes
6 answers

underscore/lodash unique by multiple properties

I have an array of objects with duplicates and I'm trying to get a unique listing, where uniqueness is defined by a subset of the properties of the object. For example, {a:"1",b:"1",c:"2"} And I want to ignore c in the uniqueness comparison. I can…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
50
votes
16 answers

Checking if all elements of a vector are equal in C++

If I have a vector of values and want to check that they are all the same, what is the best way to do this in C++ efficiently? If I were programming in some other language like R one way my minds jumps to is to return only the unique elements of the…
SJWard
  • 3,629
  • 5
  • 39
  • 54
50
votes
2 answers

Number of non repeating lines - unique count

Here is my problem: Any number of lines of text is given from standard input. Output: number of non repeating lines INPUT: She is wearing black shoes. My name is Johny. I hate mondays. My name is Johny. I don't understand you. She is wearing black…
john blackwood
  • 511
  • 1
  • 4
  • 3
48
votes
6 answers

#1062 - Duplicate entry '' for key 'unique_id' When Trying to add UNIQUE KEY (MySQL)

I've got an error on MySQL while trying to add a UNIQUE KEY. Here's what I'm trying to do. I've got a column called 'unique_id' which is VARCHAR(100). There are no indexes defined on the table. I'm getting this error: #1062 - Duplicate entry '' for…
MillerMedia
  • 3,651
  • 17
  • 71
  • 150
47
votes
5 answers

Delete all but one duplicate record

I have a table that is supposed to keep a trace of visitors to a given profile (user id to user id pair). It turns out my SQL query was a bit off and is producing multiple pairs instead of single ones as intended. With hindsight I should have…
James P.
  • 19,313
  • 27
  • 97
  • 155
47
votes
13 answers

Getting first n unique elements from Python list

I have a python list where elements can repeat. >>> a = [1,2,2,3,3,4,5,6] I want to get the first n unique elements from the list. So, in this case, if i want the first 5 unique elements, they would be: [1,2,3,4,5] I have come up with a solution…
xssChauhan
  • 2,728
  • 2
  • 25
  • 36
45
votes
14 answers

Removing duplicate objects (based on multiple keys) from array

Assuming an array of objects as follows: const listOfTags = [ {id: 1, label: "Hello", color: "red", sorting: 0}, {id: 2, label: "World", color: "green", sorting: 1}, {id: 3, label: "Hello", color: "blue", sorting: 4}, {id: 4, label:…
Andy
  • 549
  • 1
  • 6
  • 12
45
votes
2 answers

Composite PRIMARY KEY enforces NOT NULL constraints on involved columns

This is one strange, unwanted behavior I encountered in Postgres: When I create a Postgres table with composite primary keys, it enforces NOT NULL constraint on each column of the composite combination. For example, CREATE TABLE distributors (m_id…
user3422637
  • 3,967
  • 17
  • 49
  • 72
44
votes
3 answers

SQL - select distinct only on one column

I have searched far and wide for an answer to this problem. I'm using a Microsoft SQL Server, suppose I have a table that looks like this: +--------+---------+-------------+-------------+ | ID | NUMBER | COUNTRY | LANG …
Jason Lipo
  • 751
  • 2
  • 11
  • 24
43
votes
2 answers

How to assign a unique ID number to each group of identical values in a column

I have a data frame with a number of columns. I would like to create a new column called “id” that gives a unique id number to each group of identical values in the “sample” column. Example data: df <- data.frame( index = 1:30, val = c( 14L,…
jjulip
  • 1,093
  • 4
  • 16
  • 24
42
votes
12 answers

Count unique values in a column in Excel

I have an .xls file with a column with some data. How do I count how many unique values contains this column? I have googled many options, but the formulas they give there always give me errors. For example, =INDEX(List,…
Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103