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 71 times
Expert Verified
OS
Created byOguz Serdar
CM
Reviewed byCuneyt Mertayak

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

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