Difference between list and dictionary
List and dictionary are fundamentally different data structures . A list can store a sequence of objects in a certain order such that you can index into the list, or iterate over the list. Moreover, List is a mutable type meaning that lists can be modified after they have been created. Python dictionary is an implementation of a hash table and is a key-value store. It is not ordered and it requires that the keys are hashtable. Also, it is fast for lookups by key.
Elements in a list have the following characteristics:
- They maintain their ordering unless explicitly re-ordered (for example, by sorting the list).
- They can be of any type, and types can be mixed.
- They are accessed via numeric (zero based) indices.
Elements in a Dictionary have the following characteristics:
- Every entry has a key and a value
- Ordering is not guaranteed
- Elements are accessed using key values
- Key values can be of any hashtable type (i.e. not a dict) and types can be mixed
- Values can be of any type (including other dict’s), and types can be mixed
Use a dictionary when you have a set of unique keys that map to values and to use a list if you have an ordered collection of items.