From the course: Programming Foundations: Data Structures (2023)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
When to use dictionaries - Python Tutorial
From the course: Programming Foundations: Data Structures (2023)
When to use dictionaries
- [Narrator] Every data structure has its pros and cons depending on your use case. So when should you use a dictionary? Data in dictionaries are sorted in such a way that searching is much faster than other data structures. However, they do take up more space. There's also a little bit of processing involved for retrieval and insertion, but it's the same amount of processing no matter how big the dictionary is. This means that lookup, insertion, and deletion all take (O)1, or constant time, that's because it's 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. If you need to maintain a specific order, you'll likely need to use a special type of order…