Dictionary in data structure
Anuj Singh
Student, Data Science
NMIMS, Indore
Data Structure
A data structure is a specialized format for organizing, processing, retrieving and storing data. While there are several basic and advanced structure types, any data structure is designed to arrange data to suit a specific purpose so that it can be accessed and worked with inappropriate ways.
In computer programming, a data structure may be selected or designed to store data for the purpose of working on it with various algorithms. Each data structure contains information about the data values, relationships between the data and functions that can be applied to the data.
Dictionary data structure
Dictionary is one of the important Data Structures that is usually used to store data in the key-value format. Each element presents in a dictionary data structure compulsorily have a key and some value is associated with that particular key. In other words, we can also say that Dictionary data structure is used to store the data in key-value pairs. Other names for the Dictionary data structure are associative array, map, symbol table but broadly it is referred to as Dictionary.
A dictionary or associative array is a general-purpose data structure that is used for the storage of a group of objects.
Many popular languages add Dictionary or associative array as a primitive data type in their languages while other languages which don’t consider Dictionary or associative array as a primitive data type have included Dictionary or associative array in their software libraries. A direct form of hardware-level support for the Dictionary or associative array is Content-addressable memory.
The various operations that are performed on a Dictionary or associative array are:
Add or Insert: In the Add or Insert operation, a new pair of keys and values is added in the Dictionary or associative array object.
Replace or reassign: In the Replace or reassign operation, the already existing value that is associated with a key is changed or modified. In other words, a new value is mapped to an already existing key.
Delete or remove: In the Delete or remove operation, the already present element is unmapped from the Dictionary or associative array object.
Find or Lookup: In the Find or Lookup operation, the value associated with a key is searched by passing the key as a search argument.
In this code, we have created a dictionary object named players having key as integer and value as strings. We have also created functions to implement all the basic four functionalities of the dictionary that are create, delete, update, etc.
As we can see in the output of the above code, we have 4 elements as input to our dictionary object created and then update one value in the dictionary and then we deleted one value in the dictionary and in the last we have printed the final dictionary object.