Skip to main content
1270 votes
33 answers
1.6m views

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 ...
Max Frai's user avatar
  • 64.8k
854 votes
19 answers
856k views

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[...
user avatar
797 votes
16 answers
702k views

Python has an ordered dictionary. What about an ordered set?
Casebash's user avatar
  • 120k
728 votes
15 answers
1.0m views

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 ...
Daren Thomas's user avatar
  • 70.8k
661 votes
8 answers
315k views

[] = empty list () = empty tuple {} = empty dict Is there a similar notation for an empty set? Or do I have to write set()?
Johan Råde's user avatar
  • 21.7k
628 votes
15 answers
1.2m views

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(...
Muhammad Imran Tariq's user avatar
598 votes
9 answers
833k views

How do I add values to an existing set?
Alex Gordon's user avatar
  • 61.6k
580 votes
7 answers
540k views

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 ...
Omar Kooheji's user avatar
514 votes
26 answers
696k views

What is the fundamental difference between the Set<E> and List<E> interfaces?
Johanna's user avatar
  • 27.8k
486 votes
12 answers
593k views

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()
fulmicoton's user avatar
  • 16.1k
447 votes
22 answers
1.1m views

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 ...
foobar's user avatar
  • 5,128
446 votes
9 answers
1.2m views

I'd like to know if I can get the first element of a list or set. Which method to use?
user496949's user avatar
  • 86.7k
434 votes
13 answers
669k views

How do I add a list of values to an existing set?
Adam Matan's user avatar
  • 138k
426 votes
7 answers
310k views

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, ...
user116293's user avatar
  • 6,024
408 votes
4 answers
314k views

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,...
anjanb's user avatar
  • 14.2k

15 30 50 per page
1
2 3 4 5
809