12,133 questions
1270
votes
33
answers
1.6m
views
Get difference between two lists with Unique Entries
I have two lists in Python:
temp1 = ['One', 'Two', 'Three', 'Four']
temp2 = ['One', 'Two']
Assuming the elements in each list are unique, I want to create a third list with items from the first list ...
854
votes
19
answers
856k
views
How to convert an Array to a Set in Java
I would like to convert an array to a Set in Java. There are some obvious ways of doing this (i.e. with a loop) but I would like something a bit neater, something like:
java.util.Arrays.asList(Object[...
797
votes
16
answers
702k
views
Does Python have an ordered set?
Python has an ordered dictionary. What about an ordered set?
728
votes
15
answers
1.0m
views
How to retrieve an element from a set without removing it?
Suppose the following:
>>> s = set([1, 2, 3])
How do I get a value (any value) out of s without doing s.pop()? I want to leave the item in the set until I am sure I can remove it - something ...
661
votes
8
answers
315k
views
Empty set literal?
[] = empty list
() = empty tuple
{} = empty dict
Is there a similar notation for an empty set?
Or do I have to write set()?
628
votes
15
answers
1.2m
views
Convert Set to List without creating new List
I am using this code to convert a Set to a List:
Map<String, List<String>> mainMap = new HashMap<>();
for (int i=0; i < something.size(); i++) {
Set<String> set = getSet(...
598
votes
9
answers
833k
views
Append values to a set in Python
How do I add values to an existing set?
580
votes
7
answers
540k
views
C# Set collection?
Does anyone know if there is a good equivalent to Java's Set collection in C#? I know that you can somewhat mimic a set using a Dictionary or a HashTable by populating but ignoring the values, but ...
514
votes
26
answers
696k
views
What is the difference between Set and List?
What is the fundamental difference between the Set<E> and List<E> interfaces?
486
votes
12
answers
593k
views
How to check that an element is in a std::set?
How do you check that an element is in a set?
Is there a simpler equivalent of the following code:
myset.find(x) != myset.end()
447
votes
22
answers
1.1m
views
Getting an element from a Set
Why doesn't Set provide an operation to get an element that equals another element?
Set<Foo> set = ...;
...
Foo foo = new Foo(1, 2, 3);
Foo bar = set.get(foo); // get the Foo element from the ...
446
votes
9
answers
1.2m
views
How to get the first element of the List or Set? [duplicate]
I'd like to know if I can get the first element of a list or set. Which method to use?
434
votes
13
answers
669k
views
Add list to set
How do I add a list of values to an existing set?
426
votes
7
answers
310k
views
Best way to find the intersection of multiple sets?
I have a list of sets:
setlist = [s1,s2,s3...]
I want s1 ∩ s2 ∩ s3 ...
I can write a function to do it by performing a series of pairwise s1.intersection(s2), etc.
Is there a recommended, better, ...
408
votes
4
answers
314k
views
Golang why don't we have a set datastructure [closed]
I'm trying to solve a Go language exercise which requires me to have a set. I can create a set type but why doesn't the language come with one?
Go, having come from Google, where Guava also originated,...