0
can anyone explain why we need both list and dictionaries
2 Answers
+ 3
In addition to the differences in features, dictionaries are better optimized for many features, e.g. membership testing is O (1) instead of O (n). Lists tend to perform quite slowly, as a trade off for their plethora of features.
+ 1
in lists you have a collection of single items, ordered by number/position (index), and you refer to them with this index.
dictionary is a collection of pairs of items - keys and values. you refer to values using keys. dictionaries are unordered, so you can't sort them, you can't acquire "first in line" item, just because values are assigned to abstract non-ordered keys, not to some specified position.