0
0
Intro to Computingfundamentals~3 mins

Why Dictionaries and key-value pairs in Intro to Computing? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could find any piece of information instantly, no matter how big your data is?

The Scenario

Imagine you have a big phone book where you want to find a friend's phone number. Without any order, you have to flip through every page until you find their name.

The Problem

This manual search is slow and tiring. You might miss the name or get the wrong number. It's easy to make mistakes and waste time.

The Solution

Dictionaries store data as pairs: a key (like a name) and a value (like a phone number). This lets you find any value quickly by looking up its key, just like using an index.

Before vs After
Before
names = ['Alice', 'Bob', 'Carol']
numbers = ['123', '456', '789']
# To find Bob's number, search names list for 'Bob' and get number at same position
After
contacts = {'Alice': '123', 'Bob': '456', 'Carol': '789'}
# To find Bob's number, just do contacts['Bob']
What It Enables

It makes finding, adding, or changing information fast and easy, even with lots of data.

Real Life Example

Online stores use dictionaries to quickly find product prices by product ID, so you get instant results when shopping.

Key Takeaways

Dictionaries pair keys with values for quick lookups.

They save time and reduce errors compared to searching lists.

They help organize data like contacts, settings, or inventory efficiently.