Biskit :: DictList :: DictList :: Class DictList
[hide private]
[frames] | no frames]

Class DictList

source code


List of dictionaries (or similar objects). Special support is given to access and use entries in the dictionaries for filtering and sorting. Some care is taken to avoid the adding of non-allowed objects (but somehow it is, certainly, still possible).

The list can be sorted and filtered by any dictionary key, values within the dictionaries are easily accessible and can be plotted against each other.

Overriding / Extending: The class is designed to be easily adapted for holding more complex objects. In order to do so, the attribute item_type should be set to the allowed class. All objects with a get( key, default ) and a keys() method should then work out of the box. If the two methods are missing, getItemValue and getItemKeys must be overriden.

Instance Methods [hide private]
  __init__(self, lst=[], item_type=dict)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
str version(self)
Version of class.
any getItemValue(self, item, key, default=None)
Get a value from a given item (dictionary).
[ any ], getItemKeys(self, item)
Get the attribute keys used by a certain item.
any getValue(self, i, key, default=None)
Get the value of a dictionary entry of a list item.
  checkType(self, v)
Make sure v is a dictionary
dict _processNewItem(self, v, i=None)
Called before an item is added to the list.
list _processNewItems(self, lst, indices=None)
Called before list of items is added to the list.
  __setitem__(self, i, v)
Set value v of position i.
instance __getslice__(self, i, j)
Return new instance with only the given range of items.
  extend(self, lst)
Add all items to (the end of) this instance.
  append(self, v)
Append item to the end of this list.
DictList take(self, indices)
Returns DictList (or sub-class) with specified items
[ any ], keys(self)
Returns attribute keys used by the current items.
[ int ] argsortRandom(self)
Random sort.

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setslice__, count, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, lst=[], item_type=dict)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Parameters:
  • lst ([ dict ]) - list of dictionaries
  • item_type (type) - class of allowed items [ dict ]
Raises:
  • BisListError - if list contains non-item_type item.
Overrides: list.__init__

version(self)

source code 

Version of class.
Returns: str
version of class

getItemValue(self, item, key, default=None)

source code 

Get a value from a given item (dictionary). Override this method to use the DictList for entries without get() function.
Parameters:
  • item (any) - possible entry of this list
  • key (any) - dictionary key
  • default (any) - return value if key is not found (default: None)
Returns: any
any

getItemKeys(self, item)

source code 

Get the attribute keys used by a certain item. Override this method to use the DictList for entries without keys() function.
Parameters:
  • item (any) - possible entry of this list
Returns: [ any ],
list of keys

getValue(self, i, key, default=None)

source code 

Get the value of a dictionary entry of a list item.
Parameters:
  • i (int) - position in list
  • key (any) - dictionary key
  • default (any) - return value if key is not found (default: None)
Returns: any
any

checkType(self, v)

source code 

Make sure v is a dictionary
Raises:
  • BisListError - if not a dictionary

_processNewItem(self, v, i=None)

source code 

Called before an item is added to the list. Override but call.
Parameters:
  • v (dict or similar) - value
  • i (int) - anticipated index (ignored in this implementation)
Returns: dict
value

_processNewItems(self, lst, indices=None)

source code 

Called before list of items is added to the list. For efficiency, the single new items are only processed if lst is not already an instance of this class (DictList by default). Override but call.
Parameters:
  • lst ([ any ]) - list of new items
  • indices ([ int ]) - anticipated positions of the new items (default: None) defaults to indices following the current end of list
Returns: list
list

__setitem__(self, i, v)
(Index assignment operator)

source code 

Set value v of position i.
>>> lst[i] = v
Parameters:
  • i (int) - list index
  • v (any) - value
Overrides: list.__setitem__

__getslice__(self, i, j)
(Slicling operator)

source code 

Return new instance with only the given range of items.
Parameters:
  • i (int) - start list index
  • j (int) - end list index
Returns: instance
new instance with only the given range of items
Overrides: list.__getslice__

extend(self, lst)

source code 

Add all items to (the end of) this instance.

Use:
  extend( list ). 
Parameters:
  • lst ([ any ]) - list of new items
Overrides: list.extend

append(self, v)

source code 

Append item to the end of this list.

Use:
 append( dict ).
Parameters:
  • v (any) - value
Overrides: list.append

take(self, indices)

source code 
Parameters:
  • indices (array/list of int) - list positions
Returns: DictList
DictList (or sub-class) with specified items

keys(self)

source code 
Returns: [ any ],
attribute keys used by the current items.

argsortRandom(self)

source code 

Random sort.
Returns: [ int ]
indices in random order.