TalentJR

Lesson 4

Dictionaries

Key-value data storage

1What is a Dictionary?✨

A dictionary in Python is a collection of key-value pairs. It allows you to store data in a way that makes it easy to look up information using a unique key. This is similar to a real dictionary where you find a word (key) and get its meaning (value).

2Why Use Dictionaries?🎯

  • ✓ Fast data retrieval
  • ✓ Flexible and dynamic
  • ✓ Ideal for storing related data
  • ✓ Supports various data types as values

3Creating a Dictionary💡

You can create a dictionary by placing key-value pairs inside curly braces. Here’s how:

💻 code
my_dict = {
    "name": "Alice",
    "age": 12,
    "city": "Delhi"
}

This dictionary stores a person's name, age, and city.

4Accessing Values🚀

To get a value from a dictionary, use its key. Here’s an example:

💻 code
print(my_dict["name"])

This will display "Alice" on the screen.

5Modifying a Dictionary🔍

You can easily add or change values in a dictionary using keys. For example:

💻 code
my_dict["age"] = 13
my_dict["hobby"] = "reading"

Now, the age is updated, and a new key-value pair for hobby is added.

6Looping Through a Dictionary⭐

You can loop through a dictionary to access keys and values. Here’s how:

💻 code
for key, value in my_dict.items():
    print(key, ":", value)

This will print each key along with its corresponding value.

7What You'll Build This Grade🧩

  • ✓ Programs that store and manage user data
  • ✓ Interactive quizzes with questions and answers
  • ✓ Games that use scores and player information
  • ✓ Applications that require organized data storage

🎯 Practice Challenges

Master Dictionaries by completing all 3 difficulty levels

🟢 EASY

Dictionaries - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Dictionaries - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

Dictionaries - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master Dictionaries? 🚀

Complete the challenges, take the quiz and keep your learning streak going!