0

can anyone explain why we need both list and dictionaries

27th Aug 2016, 4:18 AM
Rohith Gilla
Rohith Gilla - avatar
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.
28th Aug 2016, 12:54 AM
Phileep Leep
Phileep Leep - avatar
+ 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.
27th Aug 2016, 9:10 AM
Demeth
Demeth - avatar