<<learning python>>
dictionary:
Accessed by key, not offset
Dictionaries are sometimes called associative arrays or hashes. They associate a set
of values with keys, so you can fetch an item out of a dictionary using the key under
which you originally stored it. You use the same indexing operation to get components
in a dictionary as you do in a list, but the index takes the form of a key,
not a relative offset.

Unordered collections of arbitrary objects
Unlike in a list, items stored in a dictionary aren’t kept in any particular order; in
fact, Python randomizes their left-to-right order to provide quick lookup. Keys
provide the symbolic (not physical) locations of items in a dictionary.

Variable-length, heterogeneous, and arbitrarily nestable
Like lists, dictionaries can grow and shrink in-place (without new copies being
made), they can contain objects of any type, and they support nesting to any depth
(they can contain lists, other dictionaries, and so on).

Of the category “mutable mapping”
Dictionaries can be changed in-place by assigning to indexes (they are mutable),
but they don’t support the sequence operations that work on strings and lists.
Because dictionaries are unordered collections, operations that depend on a fixed
positional order (e.g., concatenation, slicing) don’t make sense. Instead, dictionaries
are the only built-in representatives of the mapping type category (objects
that map keys to values).

Tables of object references (hash tables)
If lists are arrays of object references that support access by position, dictionaries
are unordered tables of object references that support access by key. Internally,
dictionaries are implemented as hash tables (data structures that support very fast
retrieval), which start small and grow on demand. Moreover, Python employs optimized
hashing algorithms to find keys, so retrieval is quick. Like lists, dictionaries
store object references (not copies).

posted on 2010-08-31 03:12  菜刀大侠  阅读(936)  评论(0编辑  收藏  举报