colour.utilities.Lookup#

class colour.utilities.Lookup[source]#

Bases: dict

Represent a dict-like object that provides lookup functionality by value(s).

This class extends the built-in dict to provide reverse lookup capabilities for dictionary values, enabling retrieval of keys based on their associated values. Support both single and multiple key retrieval for matching values.

Methods

References

[Mana]

Examples

>>> person = Lookup(first_name="John", last_name="Doe", gender="male")
>>> person.first_key_from_value("John")
'first_name'
>>> persons = Lookup(John="Doe", Jane="Doe", Luke="Skywalker")
>>> sorted(persons.keys_from_value("Doe"))
['Jane', 'John']
keys_from_value(value: Any) list[source]#

Return the keys associated with the specified value.

Parameters:

value (Any) – Value to find the associated keys.

Returns:

Keys associated with the specified value.

Return type:

list

first_key_from_value(value: Any) Any[source]#

Return the first key associated with the specified value.

Parameters:

value (Any) – Value to find the associated first key.

Returns:

First key associated with the specified value.

Return type:

object

__weakref__#

list of weak references to the object