nineml.utility.filter_discrete_types

nineml.utility.filter_discrete_types(lst, acceptedtypes)[source]

Creates a dictionary mapping types to objects of that type.

Starting with a list of object, and a list of types, this returns a dictionary mapping each type to a list of objects of that type.

For example:

>>> import types
>>> filter_discrete_types( ['hello',1,2,'world'], ( basestring, types.IntType) ) 
{<type 'basestring'>: ['hello', 'world'], <type 'int'>: [1, 2]}

The function checks that each object is mapped to exactly one type