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
172
votes
11 answers

How do I remove duplicate items from an array in Perl?

I have an array in Perl: my @my_array = ("one","two","three","two","three"); How do I remove the duplicates from the array?
David
  • 14,047
  • 24
  • 80
  • 101
170
votes
10 answers

Mysql: Select rows from a table that are not in another

How to select all rows in one table that do not appear on another? Table1: +-----------+----------+------------+ | FirstName | LastName | BirthDate | +-----------+----------+------------+ | Tia | Carrera | 1975-09-18 | | Nikki | Taylor …
user1006989
153
votes
5 answers

How to check if a table contains an element in Lua?

Is there a method for checking if a table contains a value ? I have my own (naive) function, but I was wondering if something "official" exists for that ? Or something more efficient... function table.contains(table, element) for _, value in…
Wookai
  • 20,883
  • 16
  • 73
  • 86
142
votes
18 answers

Checking if all elements in a list are unique

What is the best way (best as in the conventional way) of checking whether all elements in a list are unique? My current approach using a Counter is: >>> x = [1, 1, 1, 2, 3, 4, 5, 6, 2] >>> counter = Counter(x) >>> for values in…
user225312
  • 126,773
  • 69
  • 172
  • 181
141
votes
15 answers

Uniq by object attribute in Ruby

What's the most elegant way to select out objects in an array that are unique with respect to one or more attributes? These objects are stored in ActiveRecord so using AR's methods would be fine too.
sutee
  • 12,568
  • 13
  • 49
  • 61
139
votes
16 answers

How can I check if the array of objects have duplicate property values?

I need some help with iterating through array, I keep getting stuck or reinventing the wheel. values = [ { name: 'someName1' }, { name: 'someName2' }, { name: 'someName1' }, { name: 'someName1' } ] How could I check if there are two…
be-codified
  • 5,704
  • 18
  • 41
  • 65
139
votes
8 answers

How to generate unique id in Dart

I write websocket chat. How to generate unique id for user? now i use this code: id = new DateTime.now().millisecondsSinceEpoch; is there any more neat solution?
Sergey Karasev
  • 4,513
  • 4
  • 25
  • 24
137
votes
38 answers

Create a unique number with javascript time

I need to generate unique id numbers on the fly using javascript. In the past, I've done this by creating a number using time. The number would be made up of the four digit year, two digit month, two digit day, two digit hour, two digit minute, two…
Nick Petrie
  • 5,364
  • 11
  • 41
  • 50
137
votes
11 answers

.NET unique object identifier

Is there a way of getting a unique identifier of an instance? GetHashCode() is the same for the two references pointing to the same instance. However, two different instances can (quite easily) get the same hash code: Hashtable hashCodesSeen = new…
Martin Konicek
  • 39,126
  • 20
  • 90
  • 98
136
votes
7 answers

Is it safe to assume a GUID will always be unique?

I know there is a minute possibility of a clash but if I generated a batch of 1000 GUIDs (for example), would it be safe to assume they're all unique to save testing each one? Bonus question An optimal way to test a GUID for uniqueness? Bloom filter…
Tom Savage
  • 3,172
  • 4
  • 31
  • 31
132
votes
16 answers

How can I get unique values from an array in Bash?

I've got almost the same question as here. I have an array which contains aa ab aa ac aa ad, etc. Now I want to select all unique elements from this array. Thought, this would be simple with sort | uniq or with sort -u as they mentioned in that…
Jetse
  • 2,223
  • 5
  • 17
  • 12
131
votes
13 answers

Find unique lines

How can I find the unique lines and remove all duplicates from a file? My input file is 1 1 2 3 5 5 7 7 I would like the result to be: 2 3 sort file | uniq will not do the job. Will show all values 1 time
amprantino
  • 1,597
  • 4
  • 15
  • 15
121
votes
5 answers

How to display unique records from a has_many through relationship?

I'm wondering what is the best way to display unique records from a has_many, through relationship in Rails3. I have three models: class User < ActiveRecord::Base has_many :orders has_many :products, :through => :orders end class Products <…
Andy Harvey
  • 12,333
  • 17
  • 93
  • 185
121
votes
9 answers

Python: How to create a unique file name?

I have a python web form with two options - File upload and textarea. I need to take the values from each and pass them to another command-line program. I can easily pass the file name with file upload options, but I am not sure how to pass the…
MysticCodes
  • 3,092
  • 5
  • 25
  • 33
119
votes
5 answers

Getting unique items from a list

What is the fastest / most efficient way of getting all the distinct items from a list? I have a List that possibly has multiple repeating items in it and only want the unique values within the list.
domgreen
  • 1,358
  • 2
  • 8
  • 9