Page 1 - Lesson Note - DICTIONARIES
P. 1
DICTIONARY
Python Dictionary is a mutable, unordered collection of items where each item is a key-
value pair.
Syntax:
{key1:value, key2:value, key3:value, ......}
Ex. Telephone Directory, where each name is mapped to a telephone number
Dictionary Properties:
➢ Each element of a dictionary is a key:value pair
➢ Keys are unique within a dictionary, but values may not be
➢ The value of a dictionary can be of any type, but the keys must be of immutable
type, such as strings, numbers or tuples (containing only immutable entries)
➢ Dictionary is mutable. We can add new items or change the values of existing items.
➢ Dictionary is unordered, not a sequence, ordered sequence is indexed by ordinal
numbers. Accessing or traversing is through keys not by index/numbers
➢ Internally dictionaries are stored as mappings (i.e. key:value pairs of dictionaries are
linked with one another through some internal/hash function)
Dictionary Examples
Empty Dictionary