Amortized time complexity in data structures analysis will give the average time taken per operation.
For dictionary its Amortized read time is O(1), O(1) means that the number of items in a dictionary doesn’t impact the time to get the value for a particular key.
For a list, search time is O(n), where n is number of items in the list. O(n) means that as the list grows (n grows) the time to search grows proportional to n.
Another use case is json data directy fit into dictionary format and easy access. See example below.
import json
x = {
"name": "John",
"age": 30,
"married": True,
"divorced": False,
"children": ("Ann","Billy"),
"pets": None,
"cars": [
{"model": "BMW 230", "mpg": 27.5},
{"model": "Ford Edge", "mpg": 24.1}
]
}
print(json.dumps(x))
# {"name": "John", "age": 30, "married": true, "divorced": false, "children": ["Ann", "Billy"], "pets": null, "cars": [{"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1}]}
import json
# some JSON in string form:
x = '{"name": "John", "age": 30, "married": true, "divorced": false, "children": ["Ann", "Billy"], "pets": null, "cars": [{"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1}]}'
# parse x:
y = json.loads(x)
# the result is a Python dictionary:
print(y['cars'][0]['model'])