colour.utilities.filter_mapping

colour.utilities.filter_mapping(mapping: Mapping, filterers: Union[str, Sequence[str]], anchors: Boolean = True, flags: Union[Integer, RegexFlag] = re.IGNORECASE) Dict[source]

Filter given mapping with given filterers.

Parameters
  • mapping (Mapping) – Mapping to filter.

  • filterers (Union[str, Sequence[str]]) – Filterer pattern for given mapping elements or a list of filterers.

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

  • flags (Union[Integer, RegexFlag]) – Regex flags.

Returns

Filtered mapping elements.

Return type

dict

Notes

  • To honour the filterers ordering, the return value is an dict 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')  
{'Element A': <colour.utilities.common.Element object at 0x...>}
>>> sorted(filter_mapping(mapping, 'Element.*'))
['Element A', 'Element B', 'Element C']