unique

Generate unique and random code digit with MySQL

怎甘沉沦 提交于 2019-12-12 12:34:57
问题 Initial goal: I would like to generate random and unique codes (6 digits) in a table. I use a SQL query like this one to do that: SELECT SUBSTRING(CRC32(RAND()), 1, 6) as myCode FROM `codes` HAVING myCode NOT IN (SELECT code FROM `codes`) I asked me about how it will react when there will be no more available codes so I do the following test Test context: MySQL version: 5.5.20 MySQL Table: CREATE TABLE `codes` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `code` VARCHAR( 10 ) NOT

Filtering lists

末鹿安然 提交于 2019-12-12 12:22:36
问题 I want to filter repeated elements in my list for instance foo = ['a','b','c','a','b','d','a','d'] I am only interested with: ['a','b','c','d'] What would be the efficient way to do achieve this ? Cheers 回答1: Cast foo to a set, if you don't care about element order. 回答2: list( set (foo)) if you are using Python 2.5 or greater, but that doesn't maintain order. 回答3: Since there isn't an order-preserving answer with a list comprehension, I propose the following: >>> temp = set() >>> [c for c in

What is the fastest way to make a uniq array?

人走茶凉 提交于 2019-12-12 11:48:00
问题 I've got the following situation. I have got a big array of random strings. This array should be made unique as fast as possible. Now through some Benchmarking I found out that ruby's uniq is quite slow: require 'digest' require 'benchmark' #make a nice random array of strings list = (1..100000).to_a.map(&:to_s).map {|e| Digest::SHA256.hexdigest(e)} list += list list.shuffle def hash_uniq(a) a_hash = {} a.each do |v| a_hash[v] = nil end a_hash.keys end Benchmark.bm do |x| x.report(:uniq) {

Get unique objects from array based on single attribute

Deadly 提交于 2019-12-12 11:23:47
问题 Let's say we have the following: node[1].name = "apple"; node[1].color = "red"; node[2].name = "cherry"; node[2].color = "red"; node[3].name = "apple"; node[3].color = "green"; node[4].name = "orange"; node[4].color = "orange; if I use jQuery.unique(node) I will get all the original nodes because they all have a different name OR color. What I want to do is only get the nodes with a unique name, which should return node[1] (apple) node[2] (cherry) node[4] (orange) It should not return 3

Counting unique elements in Scheme

痞子三分冷 提交于 2019-12-12 10:09:32
问题 Write a recursive Scheme procedure count-dist elements that takes a list with duplicate elements and returns the number of distinct elements in the list. This is my code, but it is not working correctly. Please help! Thanks!! (define (count-dist-elements lis) (cond ((null? lis) 0) ((null? (cdr lis))0) ((member (car lis)(cdr lis))) (else(+ 1(count-dist-elements (cdr lis)))))) p/s: let it be (count-dist-elements '(1 2 1 1 2 3 4 5 5 6 6 7 7 8 8 8 9)) 回答1: It looks like you're getting pretty

Python: Unique items of list in the order that it appears

半腔热情 提交于 2019-12-12 10:08:48
问题 In Python, we can get the unique items of the list using set(list) . However doing this breaks the order in which the values appear in the original list. Is there an elegant way to get the unique items in the order in which it appears in the list. 回答1: This is an elegant way: from collections import OrderedDict list(OrderedDict.fromkeys(list)) It works if the list items are all hashable (you will know that all the list items are hashable if converting it to a set did not trigger an exception)

Make a unique list of objects Java

时光总嘲笑我的痴心妄想 提交于 2019-12-12 09:34:58
问题 I have an ArrayList filled with objects with attributes name and time. I would like to remove duplicates based on the name and keep only records with the latest time. So I have overriden equals and hashcode for name in my object and used code like this. private List<ChangedRecentlyTO> groupRecords(List<ChangedRecentlyTO> toList) { changedRecentlyList.clear(); //static list for(ChangedRecentlyTO to : toList) { if(!changedRecentlyList.contains(to)) { changedRecentlyList.add(to); } else { if

Unique Count Formula for large dataset

让人想犯罪 __ 提交于 2019-12-12 06:00:40
问题 I am having trouble determining a way to enter a 1 or 0 into an adjacent cell to indicate whether or not a value is unique when working with a large dataset. I have read of multiple methods for accomplishing this, however none of them seem efficient for my purposes: I am using an instance of Excel 2010 (so I do not have the Distinct Count feature in PivotTables, and when I try to use PowerPivot it crashes my file due to processing limitations. In this StackOverflow question: Simple Pivot

HTML Form Number Type Unique User Input

可紊 提交于 2019-12-12 05:58:32
问题 I am using the code below to ask users to rank (prioritize) which sweets they like the best. The users need to rank from 1-3 (1 being the best) <form id="form1" name="form1" method="post" action=""> <input type="number" name="cake" id="cake" required="required" max="3" min="1"/>Cake <br /> <input type="number" name="twizlers" id="twizlers"required="required" max="3" min="1"/>Twizlers <br /> <input type="number" name="taffy" id="taffy" required="required" max="3" min="1"/>Taffy <br /><br />

Select rows based on non-directed combinations of columns

梦想的初衷 提交于 2019-12-12 05:37:53
问题 I am trying to select the maximum value in a dataframe's third column based on the combinations of the values in the first two columns. My problem is similar to this one but I can't find a way to implement what I need. EDIT: Sample data changed to make the column names more obvious. Here is some sample data: library(tidyr) set.seed(1234) df <- data.frame(group1 = letters[1:4], group2 = letters[1:4]) df <- df %>% expand(group1, group2) df <- subset(df, subset = group1!=group2) df$score <-