Bootcamp Curriculum • 5 Modules • 12 Chapters • Multi-Language Runner (Python, JS, Java, C++) • Interactive Memory Trace • AI Mentor
CHAPTER 11 · OOP-BASICS6 min read

Dictionaries, HashMaps & key-value pairs

While lists store items by numerical index, Dictionaries store data by meaningful keys: `{ 'name': 'Aarav', 'role': 'Developer' }`. This makes finding and managing structured data fast and intuitive.

By the end of this chapter, you can:
  • Create and manipulate dictionaries using key-value pairs.
  • Iterate over dictionary keys, values, and items.
  • Build the Secret Blind Auction winner calculator.
Explanation DepthTailor the level of detail to your learning goal
💻 Standard College Notes

Key-value mapping, dict methods, and safe access with .get().

Dictionaries map hashable keys to values. Common methods: .get(key, default) prevents KeyErrors, .keys(), .values(), .items(), and .update().

💡Dictionaries in Python 3.7+ maintain insertion order.

Dictionary basics: Adding, Updating, Accessing

Dictionaries use curly braces `{}`. Look up any value instantly using its key.

example_1.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.

Secret Auction project logic

In a blind auction, multiple bidders submit secret bids stored in a dictionary. The program iterates through all bids to determine the highest bidder.

example_2.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.
✦ Interactive Dry-Run Visualizer

Memory Trace: Dictionary Lookups & Winner Resolution

Follow key-value iteration and state updates in memory.

STEP1 / 4
1bids = {"Aarav": 100, "Meera": 200}👉 Executing
2winner = ""
3max_bid = 0
4for b in bids:
5 if bids[b] > max_bid:
6 max_bid = bids[b]
7 winner = b
8print(winner)
VariableValue in MemoryData Type
bids['Aarav']100auto
bids['Meera']200auto
Initialize HashMap dictionary in RAM

Key-value hash table created in memory.

Console Stream (stdout)
(No output generated yet)
Line 1: bids = {"Aarav": 100, "Meera": 200}

🔧 KeyError Exception Bug

Direct square bracket access on a missing key crashed the auction system with a KeyError.

⚡ +100 XP
fix_bug.pyPython 3.10
⚡ Quick Revision Quiz

Predict The Output (2 Questions)

Question 1 of 2:
Which of these can be used as a dictionary key?
Question 2 of 2:
What is the average time complexity of looking up a key in a Python dict?

Your lightbulb moment

✧

The key takeaway
Dictionaries store data in named key-value pairs, providing fast lookups and organized data structures.

Make it yours

Try adding your own name and bid to the dictionary and verify that the winner updates accordingly.

Try editing the code in the playground above in Python, JavaScript, Java, or C++, and use the step-by-step Dry-Run Table to inspect how variables mutate in memory. If you get stuck, click the 🤖 AI Doubt Solver button on your screen for instant explanations!