logo

Study resource

Dictionaries study guide

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

At a glance

study guide

Resource type

Topic

Dictionaries

AqaA LevelComputer ScienceFundamentals of data structures

Study guide overview

  • Deeper Study Guide: Applying Dictionaries to Word Information Retrieval

    Use this guide to connect the key–value model of a dictionary to a worked word-count representation, explain the effect of ignoring letter case, and justify retrieval results precisely.

    Core model

    Start with the definition: a dictionary is a collection of key–value pairs in which the value is accessed via the associated key. In an information-retrieval example, a word can be used as the key and information about that word can be stored as the value. In the supplied example, the value is the number of occurrences of the word in the document.

    Consider the document:

    text The green, green grass grows

    To reason about its dictionary representation, identify the words, ignore letter case, and count occurrences. The becomes the; green occurs twice; grass occurs once; and grows occurs once. The resulting dictionary is:

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

    The important reasoning is not the displayed order of the pairs. The retrieval meaning comes from the association between each key and its value. A lookup using the key "green" retrieves 2, because the word occurs twice. A lookup using "the" retrieves 1, because the case-normalised word occurs once.

    Worked application in Python

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

    print(word_counts["green"]) # 2 print(word_counts["grass"]) # 1 ```

    The expression word_counts["green"] uses the key "green" to access its associated value. It does not use a numerical position. In an exam explanation, state both parts: the key being supplied and the value retrieved.

    How to structure an exam answer

    For a definition question, state that a dictionary is a collection of key–value pairs and that the value is accessed via its associated key. For a representation question, identify what the keys mean and what the values mean before presenting the pairs. For a lookup question, quote the key and follow the association to its value. For a counting question, explain that letter case is ignored and that repeated occurrences contribute to the associated count.

    Self-check

    1. What is the key in the pair "green": 2?
    2. What does the value 2 represent in the supplied document example?
    3. Why is The represented by the key the?
    4. What value should be retrieved by looking up "grows"?
    5. Why would representing the two occurrences of green as separate repeated entries fail to show the supplied dictionary representation?

    Answers should use precise terminology: a key identifies the entry, the value is the associated information, and the value is accessed through the key. The expected retrieval values are 2 for green and 1 for grows. The lower-case key reflects the instruction to ignore letter case, and the single green key with value 2 records both occurrences.

Ready to practise?

Choose your next step

Use the study guide for understanding, then switch into an active revision mode.

Related topics

Study nearby topics next