When should a dictionary be used?



When should a dictionary be used?


Dictionaries are not always the best data structure to use in your program. They use up more memory than lists, so at scale it’s important to think about why you are choosing one over the other.
Lists are great for cases when you just need a list of items and possibly their index values.
If you’re making a dictionary where the key names are just 1, 2, 3, etc., consider using a list instead. Dictionaries are great when you need to map a relationship between keys and values where the keys need meaningful names other than index numbers.

FAQ: Learn Python - Advanced Topics in Python - keys() and values()