

Dictnotes.txt - how Python's dictionary data structures are optimized - simonw
http://svn.python.org/view/python/trunk/Objects/dictnotes.txt?revision=53782&view=markup

======
onwardly
Anyone care to comment on the significance of this? (Not a programmer but
interested and trying to learn!)

The Python Data Structures Tutorial has this to say:

"Another useful data type built into Python is the dictionary (see Mapping
Types — dict). Dictionaries are sometimes found in other languages as
“associative memories” or “associative arrays”. Unlike sequences, which are
indexed by a range of numbers, dictionaries are indexed by keys, which can be
any immutable type; strings and numbers can always be keys. Tuples can be used
as keys if they contain only strings, numbers, or tuples; if a tuple contains
any mutable object either directly or indirectly, it cannot be used as a key.
You can’t use lists as keys, since lists can be modified in place using index
assignments, slice assignments, or methods like append() and extend().

It is best to think of a dictionary as an unordered set of key: value pairs,
with the requirement that the keys are unique (within one dictionary). A pair
of braces creates an empty dictionary: {}. Placing a comma-separated list of
key:value pairs within the braces adds initial key:value pairs to the
dictionary; this is also the way dictionaries are written on output.

The main operations on a dictionary are storing a value with some key and
extracting the value given the key. It is also possible to delete a key:value
pair with del. If you store using a key that is already in use, the old value
associated with that key is forgotten. It is an error to extract a value using
a non-existent key.

The keys() method of a dictionary object returns a list of all the keys used
in the dictionary, in arbitrary order (if you want it sorted, just apply the
sorted() function to it). To check whether a single key is in the dictionary,
use the in keyword."

~~~
jules
What is it that you want to know exactly?

------
martincmartin
There was a chapter on this in Beautiful Code. Cool stuff.

------
Luyt
An interesting talk about the inner workings of Python's dictionary was given
at PyCon 2010: "The Mighty Dictionary" by Brandon Craig Rhodes. Video at
<http://blip.tv/file/3332763>

It also contains stuff that applies to hashing and hashtables in general.

------
dustingetz
[http://svn.python.org/view/python/trunk/Objects/dictobject.c...](http://svn.python.org/view/python/trunk/Objects/dictobject.c?view=markup)
I got this link here but I can't find the HN listing.

