Next: Buffers
Prev: Lists
C-- data
values. Dictionaries take up more space than lists, but allow fast
searches. Only one association in a dictionary may have a given key.
Dictionary construction expressions have the following syntax:
#[[key1, value1], [key2, value2], ...]The result of a dictionary construction expression is a dictionary with the keys key1, key2, ... and the associated values value1, value2, .... The following are valid dictionary construction expressions:
#[["foo", 3], ['bar, 4], [8, [#0, 'startup]]] #[['type, 'and], ['lhs, 3], ['rhs, 0]]You can search for the value associated with a key in a dictionary using the list selection expression:
dict[key]If any of the associations in dict have the key key, the result of this expression is the value associated with that key. If key is not the key of any of the associations in dict, then the interpreter raises a
~keynf error.
You can iterate over a dictionary's associations using the for-list
statement; at each step of the for-list statement, the loop index will
contain a list [key, value] for the current
association.
The four dictionary manipulation functions dict_keys(),
dict_contains(), dict_add(), and dict_del() allow
you to manipulate dictionaries in other ways; see the descriptions of
each function for details.