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:
- Dictionaries in Python
- How to Iterate Through a Dictionary in Python
- Sorting a Python Dictionary: Values, Keys, and More
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.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
emru67 on March 16, 2024
Hi Philipp, I just print out the winner like this:
is that ok? Or there are hidden pitfalls I should be aware of?.... Thanks