From the course: Programming Foundations: Data Structures
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
When to use dictionaries - Python Tutorial
From the course: Programming Foundations: Data Structures
When to use dictionaries
- [Instructor] Every data structure has its pros and cons depending on your use case. So, when should you use a dictionary? Dictionaries are ideal when you need fast data access. They offer significantly quicker retrieval, insertion, and search times than many other data structures, though this comes at the cost of higher memory usage. In fact, these operations take O of 1 or constant time because their runtime is consistent across any input or any size of the structure. Depending on the data you're storing, dictionaries can also be useful because their key value nature allows you to store mapping relationships more easily. They can also grow and shrink in size dynamically, making them a very flexible data structure. However, if you need to maintain a specific order, a regular dictionary may not be ideal, since dictionaries don't inherently preserve order. You would need to use an ordered dictionary or sort the keys manually. Another limitation to keep in mind is that dictionary keys…
Contents
-
-
-
-
-
What is a dictionary?1m 23s
-
Create a dictionary in Python1m 40s
-
(Locked)
Mutate a dictionary in Python3m 5s
-
(Locked)
Solution: Update salary53s
-
(Locked)
Handle missing dictionary keys2m 2s
-
(Locked)
Retrieve keys and value collections from dictionaries1m 44s
-
(Locked)
Solution: Clean user preferences1m 27s
-
(Locked)
When to use dictionaries1m 22s
-
-
-
-
-
-
-