+ 1

Why dictionary is considered as an unordered collection of objects. ..

DEFINITION. ..

4th May 2020, 12:31 PM
SARTHAK JAIN
SARTHAK JAIN - avatar
3 Réponses
+ 1
Because you dont pull info out based on index like lists. list[4][2] Would pull the third item from the fifth list in list Dictionaries use keys, so it doesnt actually matter where the item is in the dictionary, you search with keys. Dict['job']['pay'] Would look for the key 'job' then inside job it would look for the key 'pay', and whatever 'pay's value is is what would be returned
4th May 2020, 12:37 PM
Slick
Slick - avatar
+ 1
A dictionary is termed an unordered collection of objects because dictionaries do not maintain any inherent order of the items based on when they were added. In older versions of Python (before 3.7), dictionaries did not preserve insertion order at all. This meant that when you accessed or printed the items, the order could vary, as dictionaries were optimized for fast lookups rather than maintaining order. Starting from Python 3.7, dictionaries do retain insertion order as an implementation detail, meaning elements appear in the order they were added when you print or iterate over them. However, they are still called "unordered" because their primary function is fast key-based access, and they are not intended to be used as ordered collections like lists or tuples. So even though they appear ordered in Python 3.7+, the emphasis is still on key-value mapping rather than sequence.
31st Oct 2024, 1:18 PM
Prantik Sarkar
Prantik Sarkar - avatar