colour.utilities.filter_mapping

colour.utilities.filter_mapping(mapping, filterers, anchors=True, flags=RegexFlag.IGNORECASE)[source]

Filters given mapping with given filterers.

Parameters
  • mapping (dict_like) – Mapping to filter.

  • filterers (unicode or object or array_like) – Filterer pattern for given mapping elements or a list of filterers.

  • anchors (bool, optional) – Whether to use Regex line anchors, i.e. ^ and $ are added, surrounding the filterer pattern.

  • flags (int, optional) – Regex flags.

Returns

Filtered mapping elements.

Return type

OrderedDict

Notes

  • To honour the filterers ordering, the return value is an OrderedDict class instance.

Examples

>>> class Element:
...     pass
>>> mapping = {
...     'Element A': Element(),
...     'Element B': Element(),
...     'Element C': Element(),
...     'Not Element C': Element(),
... }
>>> filter_mapping(mapping, '\w+\s+A')  
OrderedDict([('Element A', <....Element object at 0x...>)])
>>> sorted(filter_mapping(mapping, 'Element.*'))
['Element A', 'Element B', 'Element C']