unique

Java Set gets duplicate entry

房东的猫 提交于 2020-01-30 09:13:33
问题 JavaDoc defines set as : A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2) To verify the same, i created a very simple program: import java.util.HashSet; public class CheckHashSet { public static void main(String[] args) { HashSet<Employee> set = new HashSet<Employee>(); set.add(new Employee(10)); set.add(new Employee(10)); System.out.println(set.size()); System.out.println(new Employee(10).equals(new Employee

R summarize unique values across columns based on values from one column

馋奶兔 提交于 2020-01-30 05:30:28
问题 I want to know the total number of unique values for each column based on the values of var_1. For example: Test <- data.frame(var_1 = c("a","a","a", "b", "b", "c", "c", "c", "c", "c"), var_2 = c("bl","bf","bl", "bl","bf","bl","bl","bf","bc", "bg" ), var_3 = c("cf","cf","eg", "cf","cf","eg","cf","dr","eg","fg")) The results I am looking for would be based on the values in var_1 and should be: var_1 var_2 var_3 a 2 2 b 2 1 c 3 4 However, after trying various methods (including apply and table)

Count unique values per unique keys in python dictionary

早过忘川 提交于 2020-01-25 11:38:05
问题 I have dictionary like this: yahoo.com|98.136.48.100 yahoo.com|98.136.48.105 yahoo.com|98.136.48.110 yahoo.com|98.136.48.114 yahoo.com|98.136.48.66 yahoo.com|98.136.48.71 yahoo.com|98.136.48.73 yahoo.com|98.136.48.75 yahoo.net|98.136.48.100 g03.msg.vcs0|98.136.48.105 in which I have repetitive keys and values. And what I want is a final dictionary with unique keys (ips) and count of unique values (domains). I have laready below code: for dirpath, dirs, files in os.walk(path): for filename in

javascript unique string array case insensitive but keep one case sensitive result

风流意气都作罢 提交于 2020-01-25 07:49:07
问题 What do I mean with this? First let's look at some code I wrote: let names = ['James', 'james', 'bob', 'JaMeS', 'Bob']; let uNames = {}; names.forEach(n => { let lower = n.toLowerCase(); if (!uNames[lower]) { uNames[lower] = n; } }); names = Object.values(uNames); console.log(names); // >>> (2) ["James", "bob"] The goal here is to unique the given array case insensitive but keep one of the original inputs. I was wondering if there is a more elegant/better performing solution to this problem

get unique value from array and sum totals

不羁的心 提交于 2020-01-25 07:20:08
问题 From this Array() I want to grab the values of amount_total , shipping and partner and total them up by specific partner. So for example the partner=>2665 should have a amount_total of 41.79 + 55.95 and so on please help. I don't want to do it through SQL because I need the data as it is as well. Array ( [0] => Array ( [amount_total] => 41.79 [amount_shipping] => 4.99 [amount_partner] => 14.8 [partner] => 2665 ) [1] => Array ( [amount_total] => 55.95 [amount_shipping] => 19.96 [amount_partner

How can I select a unique element in the array?

泪湿孤枕 提交于 2020-01-25 06:47:27
问题 I'm trying to solve this task of finding the unique element inside an array. So far I managed to solve 95%, but I'm failing on 0. I get an error saying that expected 0 and got 1. I should get //10, which it does, but after I'm failing the test online. For all other values it has passed. Any ideas about how to solve this and what I'm missing here? function findOne(arr) { let x = arr[0]; for (let i of arr) { if (i === x) { continue; } else { x = i; } return x; } } console.log(findOne([3, 10, 3,

Keep all elements in one list from another

谁都会走 提交于 2020-01-25 04:18:22
问题 I have two large lists train and keep , with the latter containing unique elements, for e.g. train = [1, 2, 3, 4, 5, 5, 5, 5, 3, 2, 1] keep = [1, 3, 4] Is there a way to create a new list that has all the elements of train that are in keep using sets ? The end result should be: train_keep = [1, 3, 4, 3, 1] Currently I'm using itertools.filterfalse from how to keep elements of a list based on another list but it is very slow as the lists are large... 回答1: Convert the list keep into a set ,

Keep all elements in one list from another

隐身守侯 提交于 2020-01-25 04:17:05
问题 I have two large lists train and keep , with the latter containing unique elements, for e.g. train = [1, 2, 3, 4, 5, 5, 5, 5, 3, 2, 1] keep = [1, 3, 4] Is there a way to create a new list that has all the elements of train that are in keep using sets ? The end result should be: train_keep = [1, 3, 4, 3, 1] Currently I'm using itertools.filterfalse from how to keep elements of a list based on another list but it is very slow as the lists are large... 回答1: Convert the list keep into a set ,

Google Sheets Formula to calculate actual total duration of tasks with different start/end dates, overlaps, and gaps

丶灬走出姿态 提交于 2020-01-24 18:08:02
问题 I know I how to do this using a custom function/script but I am wondering if it can be done with a built-in formula. I have a list of tasks with a start date and end date. I want to calculate the actual # of working days ( NETWORKDAYS ) spent on all the tasks. Task days may overlap so I can't just total the # of days spent on each task There may be gaps between tasks so I can't just find the difference between the first start and last end. For example, let's use these: | Task Name | Start

Google Sheets Formula to calculate actual total duration of tasks with different start/end dates, overlaps, and gaps

久未见 提交于 2020-01-24 18:07:33
问题 I know I how to do this using a custom function/script but I am wondering if it can be done with a built-in formula. I have a list of tasks with a start date and end date. I want to calculate the actual # of working days ( NETWORKDAYS ) spent on all the tasks. Task days may overlap so I can't just total the # of days spent on each task There may be gaps between tasks so I can't just find the difference between the first start and last end. For example, let's use these: | Task Name | Start