Skip to content

Advanced Python · Week 2

Dictionaries

Step 1 of 5

Exercise 1: Introduction to Dictionaries

Welcome to Python 2, Lesson 2! Today, we'll learn about dictionaries, a powerful and flexible data structure in Python.

What is a Dictionary?

A dictionary is an unordered collection of key-value pairs. It's also known as an associative array, hash table, or hash map in other programming languages.

Here's how to create a simple dictionary:

# Create a dictionary of fruit colors fruit_colors = { "apple": "red", "banana": "yellow", "grape": "purple" } print(fruit_colors)

Now it's your turn! Create a dictionary called student_scores with the following information:

  • Alice: 85
  • Bob: 92
  • Charlie: 78

After creating the dictionary, print it to see the result.

Starter code
# Create the student_scores dictionary here

# Print the dictionary

Write your code here