Why would I use dictionaries instead of a list?

A dictionary has several advantages over a list especially in python. Dictionarys have two parts to every entry the key and the value and these are stored as pairs. This can give you more flexibility when storing data. The primary advantage would be retrieving stored values as it is much simpler to search through a dictionary.If the data your trying to store is identifiable so the data can be attributed to name name or item this might be a preferable system. One example would be storing the age of school students. You could store the age and name as a value and key pair. This would allow you to sort the dictionary for a particular student and retrieve their age. To do this with lists you would require two lists to search through or a very complicated indexing systems.

BT

Related Python Mentoring answers

All answers ▸

Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.


Write a function that takes a list of numbers as input, and outputs the average of the numbers. The function should catch any errors.


Write a recursive function to find the factorial of a number n.


How do you define a class in python