logo

Study resource

Dictionaries revision notes

Study Dictionaries with curriculum-aligned Revision Notes resources, practice links, and exam-focused support.

At a glance

revision notes

Resource type

Topic

Dictionaries

AqaA LevelComputer ScienceFundamentals of data structures

Revision notes

  • Dictionaries: Key–Value Data and Simple Information Retrieval

    What is a dictionary?

    A dictionary is a data structure containing a collection of key–value pairs. The key identifies an item, and the associated value is accessed through that key. This differs from accessing data by a numerical position: the key is the meaningful identifier used to retrieve the value.

    For example, a dictionary might associate words with numbers:

    python word_counts = {"grass": 1, "green": 2, "grows": 1, "the": 1}

    The key "green" is associated with the value 2. The value can be retrieved by supplying the key:

    python count = word_counts["green"]

    Here, count receives 2.

    Information-retrieval example

    The document “The green, green grass grows” can be represented as:

    text {"grass": 1, "green": 2, "grows": 1, "the": 1}

    Letter case is ignored, so The is treated as the. The word green occurs twice, so its associated value is 2. Each of the other words occurs once, so each has the value 1. Repeated occurrences are represented by one word key with an associated count in this example.

    A dictionary can therefore support a simple information-retrieval task: given a word as a key, retrieve the related count as its value. For example, looking up "grass" retrieves 1, while looking up "green" retrieves 2.

    Important distinctions

    • A key is used to identify or access an entry.
    • A value is the information associated with that key.
    • The key is not the same thing as the value: in the example, "green" is a key and 2 is its value.
    • The dictionary represents the words in the document and their associated counts; it is not simply a list of the words in their original order.

    Common errors

    • Treating a key as though it were the value.
    • Forgetting that the example ignores letter case, so The becomes the.
    • Giving green a value of 1 instead of counting both occurrences.
    • Listing duplicate green entries instead of representing the repeated word with its associated count.
    • Describing dictionary access as access by position rather than access via the associated key.

    When answering a question, identify the key, state its associated value, and explain how the value represents the required information.

Related topics

Study nearby topics next