colour.utilities.filter_mapping#

colour.utilities.filter_mapping(mapping: Mapping, names: str | Sequence[str]) dict[source]#

Filter the specified mapping with specified names.

Parameters:
  • mapping (Mapping) – Mapping to filter.

  • names (str | Sequence[str]) – Name for the mapping elements to filter or a sequence of names.

Returns:

Filtered mapping containing only the specified elements.

Return type:

dict

Notes

  • If the mapping is a colour.utilities.CanonicalMapping instance, then the lower, slugified and canonical keys are also used for matching.

  • To honour the filterers ordering, the return value is a dict instance.

Examples

>>> class Element:
...     pass
>>> mapping = {
...     "Element A": Element(),
...     "Element B": Element(),
...     "Element C": Element(),
...     "Not Element C": Element(),
... }
>>> filter_mapping(mapping, "Element A")
{'Element A': <colour.utilities.common.Element object at 0x...>}