A hash table (also known as associative array, lookup table, dictionary, hash)
is a way of storing values against keys. Often the keys are strings, in this
example the values are numbers.
And then add some elements to it:
You can also declare it and add some elements to it at once:
When we create the structure we just need to use the curly-braces notation.
We can look up the phone number for "Sally" using the array key.
You need to be sure that the key is in the associative array before you try to access it.
In this example we try to retrieve an entry that isn't in the list.
Before that we use the
in operator to test if the key exists.
Getting all values back
Commonly we want to loop over all of the keys in the associative array.
.keys() permits this. We can also use
list of pairs of keys and values.
Getting keys back in the right order
The keys come back in an unpredictable order. However we can sort them.