Top "Set" questions

A set is a collection in which no element is repeated, which may be able to enumerate its elements according to an ordering criterion (an "ordered set") or retain no order (an "unordered set").

Picking a random element from a set

How do I pick a random element from a set? I'm particularly interested in picking a random element from a …

java algorithm language-agnostic random set
Is there any kind of hash code function in JavaScript?

Basically, I'm trying to create an object of unique objects, a set. I had the brilliant idea of just using …

javascript hash set hashcode
Java Set retain order?

Does a Java Set retain order? A method is returning a Set to me and supposedly the data is ordered …

java sorting set
Why doesn't java.util.Set have get(int index)?

I'm sure there's a good reason, but could someone please explain why the java.util.Set interface lacks get(int …

java data-structures collections set
What is the fastest way to compare two sets in Java?

I am trying to optimize a piece of code which compares elements of list. Eg. public void compare(Set<…

java performance set
How can I add items to an empty set in python

I have the following procedure: def myProc(invIndex, keyWord): D={} for i in range(len(keyWord)): if keyWord[i] in …

python set
Getting the difference between two sets

So if I have two sets: Set<Integer> test1 = new HashSet<Integer>(); test1.add(1); test1.add(2); …

java set
In Python, when to use a Dictionary, List or Set?

When should I use a dictionary, list or set? Are there scenarios that are more suited for each data type?

python list dictionary data-structures set
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 …

lua set unique contains lua-table
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 …

python set set-intersection