Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Python Basics Exercises: Dictionaries (Summary)

Dictionaries store data as key-value pairs. They’re not sequences, so you can’t access elements by index. Instead, you access elements by their key. Dictionaries are great for storing relationships or when you need quick access to data. Like lists, dictionaries are mutable.

It’s a good idea to use a dictionary in the following cases:

  • Your data is unordered, or the order doesn’t matter.
  • You’ll need to update or alter the data during the program.
  • The primary purpose of the data structure is looking up values.

To learn more about Python dictionaries, check out:

To test your knowledge, try these quizzes:

This video course is part of the Python Basics series, which accompanies Python Basics: A Practical Introduction to Python 3. Now that you’ve mastered dictionaries, you can check out the other Python Basics courses.


Sample Code (.zip)

2.1 KB

Course Slides (.pdf)

6.1 MB

00:00 Congratulations on finishing the exercise and solving the challenge. In this course, you practiced how to create dictionaries, work with dictionary values, check the existence of dictionary keys, and iterate over dictionaries.

00:15 If you want to deepen your knowledge about dictionaries, then I have some additional resources for you. The first tutorial, “Dictionaries in Python,” repeats the basics that you learned in the “Python Basics: Dictionaries” video course, and you’re trained in this one.

00:30 On top of that, you’ll learn about dictionary methods that can be super handy when working with dictionaries in this Python Exercises video course. You also trained how to loop over dictionaries, but you can go way deeper there in “How to Iterate Through a Dictionary in Python.” You’ll take a deep dive.

00:47 You know a few things about this already, but I bet that you will learn something new in this tutorial.

00:53 And the third tutorial I want to recommend is “Sorting a Python Dictionary: Values, Keys, and More.” In this tutorial, you’ll get a lowdown on sorting Python dictionaries.

01:04 By the end, you’ll be able to sort by key, value, or even nested attributes, but you won’t stop there. You’ll go on to measure the performance of variations when sorting and comparing different key-value data structures.

01:17 So if you haven’t gotten enough with dictionaries in the Python Basics course, these three resources are definitely worth checking out.

01:26 And that’s all I got for you today. Thanks for joining me on this video course, and until next time, on realpython.com.

Avatar image for emru67

emru67 on March 16, 2024

Hi Philipp, I just print out the winner like this:

for ship, captain in captains.items():
    if ship not in winners.values():
        print(f"Better luck next time, Captain {captain}!")

print(f"Congratulations, Captain {captains[winners[1]]}.")

is that ok? Or there are hidden pitfalls I should be aware of?.... Thanks

Become a Member to join the conversation.