They are,
When to use a dictionary?
Storing elements as key-value pairs
Quick access to data is required
DICTIONARY | LIST |
---|---|
Access using keys | Access using index |
Collection of key-value pairs | Collection of elements |
No duplicate items | Allows duplicate items |
Creating an empty dictionary
my_first_dict = {}
print(my_first_dict)
prints, (an empty dict)
{}
Creating using curly to initialize dictionary
scores = {
'Shafni' :80,
'Ann' :94,
'Kamal' :83
}
#prints the entire score
print(scores)
#prints Kamal's and Shafni's scores
print(scores['Kamal'])
print(scores.get('Shafni'))