A dictionary (also called associative array, associative container, map, mapping, hash and index) is an abstract data type containing keys and values where each key is associated with a value.
A dictionary is similar to a mathematical function with a finite domain.
A dictionary is a data structure that is commonly used as means of lookup. It is similar to a list in that it is considered linear, except that you don't use the index for the value, the keys are used instead. The keys and values may have any value in a generic implementation. Keys are objects used to lookup for the values in the dictionary.
For example, consider the usual definition of a dictionary. The keys are the words themselves that you may look up, while the definition of the word are the values. Another example is a telephone directory, where the names are the keys while the numbers are the values.
Common methods with a dictionary are:
- Add - parameters: key, value - Adds a new key to the dictionary and associates it with a value.
- Get/lookup - parameter: key - Finds the value associated with the specified key.
- Set/assign - parameter: key - Changes the value associated with the specified key.
- Remove - parameter: key (or value if implemented) - Removes the key and value pair from the dictionary.