4.2.7 Dictionaries Flashcards
(4 cards)
Define Dictionaries.
A collection of key-value pairs in which the key value is accessed via the associated key.
Dictionary is unordered as value is retrieved by key than position.
What are some standard dictionary operations?
- retrieve a value associated with a particular key
- insert a new key-value pair into the collection
- remove a key-value pair from the collection
- update a value associated with a key
How does using a key make dictionaries operate more efficiently?
Using a key allows direct access to items stored within the collection.
This provides much quicker access to unordered data than searching through the data set using a linear search and will also outperform a binary search.
Key-value retrieval is a technique widely used in various high-performance systems, such as caches and databases.
How to retrieve a value from the dictionary?
To retrieve a value, you must use the key, this will return the associated data value.
The key is used in the same way that an index is used for an array.