colour.utilities.filter_mapping#

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

Filter given mapping with given names.

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

  • names (Union[str, Sequence[str]]) – Name for given mapping elements or a list of names.

Returns:

Filtered mapping elements.

Return type:

dict

Notes

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

  • To honour the filterers ordering, the return value is a dict class 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...>}