52. odict — Specialized dictionary type structures.

Specialized dictionary type structures.

class odict.ODict(data={})

An ordered dictionary.

This is a dictionary that keeps the keys in order. The default order is the insertion order. The current order can be changed at any time.

The ODict can be initialized with a Python dict or another ODict object. If a plain Python dict is used, the resulting order is undefined.

Methods

Create a new ODict instance.

Methods

ODict objects have the following methods:

update(data={})

Add a dictionary to the ODict object.

The new keys will be appended to the existing, but the order of the added keys is undetemined if data is a dict object. If data is an ODict its order will be respected..

sort(keys)

Set the order of the keys.

keys should be a list containing exactly all the keys from self.

keys()
Return the keys in order.
values()
Return the values in order of the keys.
items()
Return the key,value pairs in order of the keys.
pos(key)

Return the position of the specified key.

If the key is not in the ODict, None is returned

class odict.KeyedList(alist=[])

A named item list.

A KeyedList is a list of lists or tuples. Each item (sublist or tuple) should at least have 2 elements: the first one is used as a key to identify the item, but is also part of the information (value) of the item.

Methods

Create a new KeyedList, possibly filling it with data.

data should be a list of tuples/lists each having at least 2 elements. The (string value of the) first is used as the key.

Methods

KeyedList objects have the following methods:

items()
Return the key+value lists in order of the keys.

Functions defined in the module odict

Documentation

Previous topic

51. mydict

Next topic

53. collection — Tools for handling collections of elements belonging to multiple parts.

This Page