AgentDock
1.7k
Prompt LibraryEducationCodingDictionary and Key-Value Practice Generator

Dictionary and Key-Value Practice Generator

Generate a trace of dictionary or object manipulation code step by step, or produce a key-value practice problem and check a submitted attempt against it.

Used 72 times

Prompt Template

You are an instructor who has noticed that dictionaries and objects confuse beginners in a specific, recurring way, not the syntax of writing one, but predicting what happens when a key that already exists gets written to again, or when code tries to read a key that was never set in the first place, and both of those moments deserve to be traced explicitly rather than glossed over.

My language is [LANGUAGE:select:Python,JavaScript]. Work in [MODE:select:trace my own code,generate a practice problem] mode.

If I chose trace my own code, my code is:

[CODE]

If I left [CODE] blank, ask me to paste actual dictionary or object manipulation code before doing anything else instead of inventing an example. Walk through the operations in order, and for each one, state what kind of operation it is, adding a new key, overwriting an existing key's value, reading a key's value, checking whether a key exists, deleting a key, or iterating over keys or values, and print the full current state of the structure immediately after that operation completes. If an operation reads a key that does not exist, state explicitly what happens as a result in [LANGUAGE], whether that raises an error, such as Python's `KeyError`, or returns a specific value, such as JavaScript's `undefined`, since that exact behavior is one of the most common sources of a beginner bug.

If I chose generate a practice problem, my difficulty is [DIFFICULTY:select:beginner,intermediate]. Generate a small, concrete problem that requires building a dictionary or object from a short list of raw data, such as counting how many times each word appears in a short sentence, or grouping a list of items by a shared category, sized appropriately for [DIFFICULTY]. State the problem and the starting data clearly, then wait for my attempt, whether that is real code, a description of my approach, or a hand-worked version of the final structure, rather than solving it for me immediately. When I share my attempt, check it against the correct process step by step, confirming what I got right before pointing to exactly which step my approach diverged from the correct one, particularly whether I handled the case of seeing a key for the first time differently than seeing one that had already been added.

Close by asking whether nested access, a dictionary or object containing another dictionary or object as one of its values, is something I want covered next, since that layer of nesting is the natural next difficulty step once flat key-value operations feel solid.

Variables
4

select
select
text
select

Use this prompt anywhere

10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.

Get Early Access

About Dictionary and Key-Value Practice Generator

Writing a dictionary or object is rarely the confusing part for beginners. Predicting what happens when a key that already exists gets written to again, or when code tries to read a key never set at all, is where the real confusion lives, and most explanations never trace those two moments explicitly.

Trace mode reads your own [CODE] in Python or JavaScript and walks through every operation in order, naming what kind it is, adding a key, overwriting one, reading one, checking existence, deleting, or iterating, and prints the full structure's state immediately after each change. If an operation reads a key that doesn't exist, the exact resulting behavior for your language gets stated directly, Python's KeyError or JavaScript's undefined, one of the most common sources of a beginner bug.

Practice mode generates a small problem requiring you to build a dictionary or object from raw data, counting word frequency in a sentence or grouping items by category, sized to your [DIFFICULTY]. It waits for your actual attempt, real code, a described approach, or a hand-worked structure, before responding, then checks it step by step, paying particular attention to whether you handled a key's first appearance differently than one already added, the exact distinction most beginner bugs here come down to. Run it in the Dock Editor to build a practice log, pair with the higher-order function practice generator for array transformations like map and filter, or the hashing explainer to see what a dictionary is actually doing underneath.

How to Use Dictionary and Key-Value Practice Generator

1

Pick Your Language and Mode

Copy this prompt and paste it into the Dock Editor, ChatGPT, Claude, or Gemini. Set [LANGUAGE] to Python or JavaScript, and [MODE] to trace my own code or generate a practice problem.

2

Paste Your Code or Set Your Difficulty

In trace mode, paste dictionary or object code into [CODE]. In practice mode, set [DIFFICULTY] and a problem requiring key-value grouping or counting gets generated.

3

Watch the Structure After Every Operation

Trace mode prints the full current state of your dictionary or object immediately after each add, overwrite, read, check, delete, or iteration.

4

See What Happens When a Key Doesn't Exist

Reading a missing key's exact behavior for your language gets stated explicitly, whether that's an error or a specific fallback value.

5

Attempt the Practice Problem Before Checking It

Practice mode waits for your real attempt, code, an approach, or a hand-worked structure, then checks it step by step against the correct process.

Who Uses Dictionary and Key-Value Practice Generator

Students Learning Dictionaries or Objects for the First Time

Trace a small piece of code adding and reading keys, watching the full structure change after each operation instead of only seeing the final result.

Students Debugging a KeyError or Undefined Value

Paste the code that's throwing an unexpected error and get each operation traced to find exactly which read hit a key that was never actually set.

Students Practicing Word Frequency or Grouping Problems

Work through a generated practice problem that requires building a dictionary from raw data, a common intro assignment pattern, and get your own attempt checked step by step.

Self-Taught Developers Comparing Python and JavaScript

See how the same key-value operations, especially reading a missing key, behave differently between Python dictionaries and JavaScript objects.

Frequently Asked Questions

You Might Also Like

Discover more prompts that could help with your workflow.

Skip the copy-paste

10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.

Join the waitlist for exclusive early access to the AgentDock Platform