next up previous contents index
Next: 2.1.7 Other Built-in Types Up: 2.1 Built-in Types Previous: Mutable Sequence Types

2.1.6 Mapping Types

A mapping object maps values of one type (the key type) to arbitrary objects. Mappings are mutable objects. There is currently only one standard mapping type, the dictionary. A dictionary's keys are almost arbitrary values. The only types of values not acceptable as keys are values containing lists or dictionaries or other mutable types that are compared by value rather than by object identity. Numeric types used for keys obey the normal rules for numeric comparison: if two numbers compare equal (e.g. 1 and 1.0) then they can be used interchangeably to index the same dictionary entry.

     

Dictionaries are created by placing a comma-separated list of key:,value pairs within braces, for example: {'jack':,4098, 'sjoerd':,4127} or {4098:,'jack', 4127:,'sjoerd'}.

The following operations are defined on mappings (where a is a mapping, k is a key and x is an arbitrary object):

tableiii640

          

   

, Notes:

(1)
Raises an exception if k is not in the map.

(2)
Keys and values are listed in random order.



guido@cnri.reston.va.us