Dictionary vs Set
People think a set is just a dictionary with no values, because in Python both are written with curly brackets. A dictionary pairs each key with a value, so you look a value up by its key. A set holds single values, each one once, and has nothing to look up. In Python, {} on its own makes an empty dictionary. An empty set is written set().
Dictionary
A collection of key and value pairs. You look a value up by its key.
A dictionary is a collection that stores pairs: a key and a value. You look a value up by its key, not by a number. Each key appears only once, like each word in a real dictionary. Python calls it a dict, JavaScript uses an object or a Map, and many others call it a map. It is the fastest way to find one thing by its name.
Set
A group of values with no repeats. Each value is in it just once.
A set is a collection where each value can appear only once. Add the same value twice and the set still holds one copy. Most sets keep no order, so there is no first or last item. Sets are quick at answering one question: is this value in here? They are handy for removing repeats from a list.
In one line
- Dictionary
- A collection of key and value pairs. You look a value up by its key.
- Set
- A group of values with no repeats. Each value is in it just once.